blob_id stringlengths 40 40 | language stringclasses 1
value | repo_name stringlengths 4 137 | path stringlengths 2 355 | src_encoding stringclasses 31
values | length_bytes int64 11 3.9M | score float64 2.52 5.47 | int_score int64 3 5 | detected_licenses listlengths 0 49 | license_type stringclasses 2
values | text stringlengths 11 3.93M | download_success bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|
e25e9111cd70cf34a724e6d56bb04f602b9af6f5 | Ruby | chenxiaobin001/CIS597 | /hw3/tmp/testroman.rb | UTF-8 | 502 | 2.875 | 3 | [] | no_license | require_relative 'romanbug'
require 'minitest/autorun'
class TestRoman < MiniTest::Test
def test_simple
assert_equal("i", Roman.new(1).to_s)
assert_equal("ix", Roman.new(9).to_s)
end
def test_more
assert_equal("ii", Roman.new(2).to_s)
assert_equal("iii", Roman.new(3).to_s)
end
def te... | true |
e1f42d68e0bd0c9709355f10c54f14352478399f | Ruby | tlemburg/christmaslist | /models/user.rb | UTF-8 | 730 | 2.609375 | 3 | [] | no_license | require 'active_record'
require 'bcrypt'
require 'models/gift'
class User < ActiveRecord::Base
has_many :wanted_gifts, foreign_key: "wanter_id", class_name: "Gift"
has_many :gifted_gifts, foreign_key: "gifter_id", class_name: "Gift"
include BCrypt
def wanted_gifts_for_event(event_id)
wanted_gifts.all.sele... | true |
e54e8d41933225370feef4f51ea8dde0378f8e45 | Ruby | cinexin/RubyTutorial | /10_Object_oriented_programming_II/martial_arts_module.rb | UTF-8 | 423 | 3.6875 | 4 | [] | no_license | # Exercise 13 - See? That's how we can simulate multiple inheritance in Ruby!!
module MartialArts
def swordsman
puts "I'm a swordsman."
end
end
class Ninja
include MartialArts
def initialize(clan)
@clan = clan
end
end
class Samurai
include MartialArts
def initialize(shogun)
@shogun = shogun
end
e... | true |
2e4789f3c5cf27dbb910a768f6f981b7275a66d2 | Ruby | indepthae/indepth-core | /lib/gradebook/gradebook_detailed_report_generator.rb | UTF-8 | 381 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | class GradebookDetailedReportGenerator
attr_accessor :param
def initialize(param)
# @id = param[:exam].split('_').last.to_i
@type = param[:exam].split('_').first
@param = param
end
def create_report
case @type
when "term"
GenerateDetailedTermReport.new(@param)
when "plan"
... | true |
781e41ce4611af923cec4a6436ab0f398833afa3 | Ruby | andrew/codetriage | /app/models/email_decider.rb | UTF-8 | 1,285 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # This class is used to determine the rate at which emails are sent.
# We look at two parameters, the last day the user clicked on a link and the
# last day we sent them an email. The idea is that we should send more active users
# more emails. Less active users should get fewer emails so that it's less annoying.
class... | true |
2953ca726e176724ac1e7dc0e3438893f643fde8 | Ruby | ChrisRG/CodingChallenges | /codewars/scramble_str.rb | UTF-8 | 971 | 4.09375 | 4 | [] | no_license | # Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.
# Notes:
# Only lower case letters will be used (a-z). No punctuation or digits will be included.
# Performance needs to be considered
# Examples
# scrambl... | true |
c154fbf88c5b8fba7523d6e9bf758d1eb9e87594 | Ruby | bbatsov/ruby-lint | /spec/ruby-lint/virtual_machine/assignments/arrays_spec.rb | UTF-8 | 2,567 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe RubyLint::VirtualMachine do
describe 'array assignments' do
example 'assign an empty array' do
defs = build_definitions('numbers = []')
value = defs.lookup(:lvar, 'numbers').value
value.type.should == :array
value.instance?.should == true
value... | true |
d7a8cfed172e16eab6205c3742ab11158793c049 | Ruby | Springest/idid | /lib/idid/interactive.rb | UTF-8 | 2,011 | 2.671875 | 3 | [
"MIT"
] | permissive | module Idid
module Interactive
class << self
def create_config
status "Please take a moment to create a new configuration.."
config = user_config
config['delivery'] ||= {}
user_config_from_key 'account_type', "What kind of iDoneThis account do you have? (personal|team)", 'p... | true |
9ec7d722c3800a3b1cdb81b6565696aabce32a3c | Ruby | dbushey/oxford-comma-v-000 | /lib/oxford_comma.rb | UTF-8 | 369 | 3.546875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def oxford_comma(array)
if array.length === 1
#turn the array into a str
array.join
elsif array.length === 2
#str1 "and" str2
array.join(" and ")
else
#turn the array into str, all elements separeted by "," "and" last element
lastelem = array.pop
firststr = array*", "
str = firstst... | true |
e33dcc67cc24911e6e7e7ce752ea30e7feb86317 | Ruby | krbrennan/ruby | /rspec_1/lib/02_calculator.rb | UTF-8 | 382 | 3.625 | 4 | [] | no_license | def add(num1,num2)
num1 + num2
end
def subtract(num1,num2)
num1 - num2
end
def sum(arr)
if arr.empty?
return 0
end
arr.reduce(&:+)
end
def multiply(*nums)
nums.reduce(&:*)
end
def divide(num1,num2)
num1 / num2
end
def power(num1,num2)
num1 ** num2
end
def factorial(num)
return 1 if num == 0
... | true |
cd2097327c257ed6ab5859f5b2ff5e90da9f2f53 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/simple-linked-list/4486793bea32460292c9fb17dacce7f8.rb | UTF-8 | 402 | 3.0625 | 3 | [] | no_license | class Element
attr_reader :datum, :next
def self.to_a(obj)
obj.to_a
end
def self.from_a(obj)
first, *rest = obj.to_a
new(first, from_a(rest)) if first
end
def initialize(datum, obj)
@datum = datum
@next = obj
end
def to_a
[datum, *self.next.to_a]
end
def reverse(obj = ni... | true |
4ec401a7ba2bdac2d0479a87390db4fb6394850b | Ruby | maxlvl/LS | /ruby basic exercises/variable_scope/varscope6.rb | UTF-8 | 474 | 3.875 | 4 | [] | no_license | a = 7
def my_value(b)
b = a + a
end
my_value(a)
puts a
# Even though a is defined before my_value is defined, it is not visible inside my_value. Methods are self contained with respect to local variables; local variables defined inside the method are not visible outside the method, and local variables defined outs... | true |
26ddca91ec781cd20f6e7c30f155805dcbab3a04 | Ruby | monkeyx/throneofthestars | /lib/locatable.rb | UTF-8 | 3,078 | 2.703125 | 3 | [] | no_license | module Locatable
def location
return nil if self.location_type.blank? || location_id == 0
k = Kernel.const_get(self.location_type)
begin
return k.find(location_id)
rescue
self.location_id = 0
self.location_type = nil
save
return nil
end
end
def location=(l)
if... | true |
a11f5e2f32f638388481c620cdb2c9694eb06991 | Ruby | dakimaru/Altcoin | /app/models/message.rb | UTF-8 | 753 | 2.578125 | 3 | [] | no_license | # == Schema Information
#
# Table name: messages
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# content :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Message
include ActiveModel::Validations
inclu... | true |
2cde66f2892e66e1fffcfa1964d612ab96d63b31 | Ruby | jeromesardoma/LS_Exercises | /ITPWR/arrays/ex8.rb | UTF-8 | 43 | 3.21875 | 3 | [] | no_license | a = [1,2,3]
b = a.map{ |e| e + 2 }
p a
p b | true |
8f7404048f59f29dc40af214ae6f10e0ca1429f2 | Ruby | AMaleh/glimmer-dsl-swt | /samples/elaborate/tic_tac_toe.rb | UTF-8 | 2,445 | 2.71875 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2007-2021 Andy Maleh
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# d... | true |
d9aa85e1382582854b78645523970a6b4afbd48d | Ruby | ajosephides/bank_account_makers | /spec/features/view_statement_spec.rb | UTF-8 | 997 | 3.078125 | 3 | [] | no_license | # frozen_string_literal: true
# A user can view their statement. It should consist of all the transactions
# and the balance at each step. It should be in reverse chronological order (oldest
# transaction at the end).
require 'timecop'
require 'account'
describe Account do
let(:account) { Account.new }
describe ... | true |
5eb4978afd1d3dcb14de106b4b14062b2bf5f59f | Ruby | nathangthomas/module_3_diagnostic | /app/services/station_service.rb | UTF-8 | 1,281 | 2.640625 | 3 | [] | no_license | # class StationService
#
# def stations
# get_json("https://developer.nrel.gov/api/alt-fuel-stations/v1/nearest.json?api_key=tSv9DiMHjCHNHEE7mkoqdopdKcHy6ihFlYwFTTxj&format=json&location=street, city, state, postal code&zip =80302&radius=6&fuel_type=LPG, ELEC&limit=10")
# end
#
# private
# def get_json(url)... | true |
f9c8cdcec652e641ecb7575d5b0ef0b7258d9b70 | Ruby | adsimpson/xibit | /lib/xibit/serializer/camelize.rb | UTF-8 | 1,005 | 2.609375 | 3 | [] | no_license | class Xibit::Serializer
module Camelize
extend ActiveSupport::Concern
included do
class_attribute :_camelize
end
# CLASS METHODS
module ClassMethods
# Sets camelization for attribute names
#
# :lower = camelCaseLikeThis
# true = CamelCaseLikeThis... | true |
ff9ce75427ec18ae43962036ed97051947fce5bb | Ruby | yrlihuan/Hermes | /fetcher/cap.sh.rb | UTF-8 | 1,523 | 2.640625 | 3 | [] | no_license | #
# filename: fetcher/cap.sh.rb
# author: yrlihuan@gmail.com
#
require "rubygems"
require "json"
require "nokogiri"
require File.expand_path("../../accessor/all.rb", __FILE__)
require File.expand_path("../base.rb", __FILE__)
module Fetcher
class CapSh < Base
def run(force_update=false)
accessor = accesso... | true |
471bc07ddd4fe70b3e7f69f4a5fc41a27d7d0579 | Ruby | jonnymoore12/tic_tac_toe | /tic_tac_toe.rb | UTF-8 | 1,220 | 3.84375 | 4 | [] | no_license | require './lib/game'
require './lib/board'
require './lib/player'
require './lib/computer_player'
puts "Welcome to tic tac toe!"
puts "A multiplayer, command-line game"
puts "================================"
sleep 1
puts "Would you like to play the one or two player game?"
players = ''
while players != "1" && players... | true |
e337ec8fbf0edec8a55099f8b7efc1850b67c33e | Ruby | ysk1180/ruby_design_pattern | /iterator_external.rb | UTF-8 | 389 | 3.5625 | 4 | [] | no_license | class ArrayIterator
def initialize(array)
@array = array
@index = 0
end
def has_next?
@index < @array.length
end
def next_item
value = @array[@index]
@index += 1
value
end
end
design_patterns = ['template_method', 'strategy', 'observer']
i = ArrayIterator.new(design_patterns)
whi... | true |
f865e43227131626aaa8d101133db986831b7132 | Ruby | where/rack-parser | /test/parser_test.rb | UTF-8 | 2,383 | 2.625 | 3 | [
"MIT"
] | permissive | require File.expand_path('../teststrap', __FILE__)
class FooApp
def call(env); env; end
end
context "Rack::Parser" do
context "default configuration" do
setup do
Rack::Parser.new(FooApp.new).content_types
end
asserts(:[],'application/xml').kind_of Proc
asserts(:[],'application/json').kind_... | true |
574a7cff505e8d7062344a830dc47dd797845ebf | Ruby | mehagel/phase_one_additional_stuff | /2013-06-08_sat/rr.rb | UTF-8 | 2,242 | 3.953125 | 4 | [] | no_license | require_relative 'racer_utils'
class RubyRacer
attr_reader :players, :length
def initialize(players, length = 30)
@players = players
@length = length
make_track
@current_location = []
@players.times do |current_player|
@current_location[current_player] = 0
end
@dice = Die.new... | true |
6ad17611aadeddc699a708d258e58feb0bd19337 | Ruby | jonallured/tremendous_pixels | /app/models/image_tweeter.rb | UTF-8 | 543 | 2.65625 | 3 | [] | no_license | class ImageTweeter
def self.announce(image)
new(image).announce
end
def initialize(image)
@image = image
end
def announce
client.update_with_media text, file
end
private
def client
@client ||= TwitterClient.generate
end
def text
"http://tremendouspixels.com/images/#{@image.i... | true |
8646ae6db8da09e0d55833a87481c7a1d70d476d | Ruby | jtran/gcode-vm | /lib/gcode_vm/transformers/not_condition.rb | UTF-8 | 250 | 2.875 | 3 | [
"MIT"
] | permissive | module GcodeVm
# A condition that negates another condition.
class NotCondition
attr_accessor :condition
def initialize(condition:)
@condition = condition
end
def call(obj)
! @condition.call(obj)
end
end
end
| true |
cbe09729953eae85db38cf308ecb3666a71ca82f | Ruby | bycdiaz/my-enumerable-methods | /my_all.rb | UTF-8 | 362 | 3.796875 | 4 | [] | no_license | module Enumerable
def my_each
i = 0
while i < self.size
yield(self[i])
i += 1
end
self
end
def my_all
result = false
self.my_each {|elem| yield(elem) ? result = true : result = false }
result
end
end
puts [100,54,1,2,3,4].my_all { |num| num.is_a? Integer }
puts [100,54,... | true |
0e1cb2fe0f305cdb00244ab4f0624355d7c63fc2 | Ruby | sbal13/oxford-comma-prework | /lib/oxford_comma.rb | UTF-8 | 249 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def oxford_comma(array)
string = ""
case array.length
when 1
string << array[0]
when 2
string << array[0] + " and " + array[1]
else
array.each{|x| x == array.last ? string << "and #{x}" : string << "#{x}, "}
end
string
end
| true |
3a877c4ba80f7a029fa72f11c48ca1627f51d0a4 | Ruby | benkbaron/chess | /chess/Pieces/queen.rb | UTF-8 | 291 | 3.15625 | 3 | [] | no_license | require_relative 'sliding_piece'
class Queen < Piece
include SlidingPiece
def initialize(board, pos, color)
super
@symbol = 'Q'
end
DELTAS = [[1,1],[1,0],[0,1],[1,-1],[-1,1],[-1,0],[-1,-1],[0,-1]]
def valid_move?(end_pos)
moves(DELTAS).include?(end_pos)
end
end
| true |
ac0dc4487d50a5ec9d2faf7428d32288d992b5d9 | Ruby | kdefliese/learn-ruby-the-hard-way-exercises | /ex11.rb | UTF-8 | 570 | 4.5625 | 5 | [] | no_license | #gets.chomp takes the user input and chomps any new lines off the end!
print "How old are you? "
age = gets.chomp
print "How tall are you? "
height = gets.chomp
print "How much do you weigh ?"
weight = gets.chomp
#uses string substitution to include the variables that are storing user input in a string
puts "So, you'r... | true |
1c84e48f0efc8664928f9c55e8bdd4cb7ba69666 | Ruby | Alippok/Shoosapp | /specs/shoe_order_spec.rb | UTF-8 | 864 | 2.890625 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../models/shoe_order.rb')
class TestShoeOrder < MiniTest::Test
def setup
params = {
"first_name" => "Johnny",
"last_name" => "Bloggs",
"first_address_line" => "23 Crag Street",
"city" => "Edinburgh",
"postcode" =>... | true |
9c4ef1691f5243f0673df86d7d16e766c993bb83 | Ruby | hangnguyenthuy/Liveup_web_test | /test.rb | UTF-8 | 951 | 2.78125 | 3 | [] | no_license | require 'uri/http'
require 'net/http'
require 'json'
@base_url = "http://api.viki.io/v4/videos.json?app=100250a&per_page=10"
def get_response_by_json(page_number)
url = "#{@base_url}&page=#{page_number}"
res = Net::HTTP.get_response(URI(url))
JSON.parse(res.body)
end
more_page = true
hd_flag_true_count = 0
hd_... | true |
9a835558357bf30217d6101291abd9a377646347 | Ruby | camertron/prebundler | /lib/prebundler/gemfile_subset.rb | UTF-8 | 2,339 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'set'
module Prebundler
class GemfileSubset
attr_reader :gemfile, :included_gems, :additional_gems, :raw
def self.from(*args)
new(GemfileInterpreter.interpret(*args))
end
def initialize(gemfile)
@gemfile = gemfile
@included_gems = Set.new
@additional_gems = []
... | true |
2f25ce66f8939052993a2a9f4051452a91c301e4 | Ruby | CodeCoreYVR/class-notes-sept-2017 | /ruby-hashes-functions/bc_cities.rb | UTF-8 | 341 | 3.15625 | 3 | [] | no_license | bc_cities_population = {vancouver: 2135201, victoria: 316327, abbotsford: 149855, kelowna: 141767, nanaimo: 88799, white_rock: 82368, kamloops: 73472, chilliwack: 66382 }
bc_cities_population.each do |city, pop|
if pop > 100_000
puts "#{city.capitalize} is a large city"
else
puts "#{city.capitalize} is a s... | true |
4a6ecca9e9bb5265b83b963b8f7fe92599859ed9 | Ruby | nanutza/herro_foo | /ruby/grove/apple_tree.rb | UTF-8 | 279 | 2.765625 | 3 | [] | no_license | require_relative 'fruit_tree'
class AppleTree < FruitTree
def initialize(age=0)
super
@mature_age = 5
@death_age = 45
@max_height = 26
@height_inc = 2
end
def pass_growing_season
super
rand(400..600).times { @crop << Apple.new } if self.mature?
end
end | true |
3053048307c38b699f517f7bcb9ff510901687a4 | Ruby | smithWEBtek/ttt-8-turn-q-000 | /lib/turn.rb | UTF-8 | 1,190 | 3.9375 | 4 | [] | no_license | def display_board(arg)
puts " #{arg[0]} | #{arg[1]} | #{arg[2]} "
puts "-----------"
puts " #{arg[3]} | #{arg[4]} | #{arg[5]} "
puts "-----------"
puts " #{arg[6]} | #{arg[7]} | #{arg[8]} "
end
def move(board, position, value = "X")
board[(position.to_i)-1] = value
end
def valid_move?(board,posi... | true |
fdd37eb17510e9121d463941db669c4ffe7d2eaf | Ruby | bpourian/oystercard | /spec/station_spec.rb | UTF-8 | 339 | 2.53125 | 3 | [] | no_license | require 'station'
describe Station do
context "Should create a station class" do
subject(:station){described_class.new("Kings Cross", 2)}
it "should expose zone variable" do
expect(station.zone).to eq 2
end
it "should expose name variable" do
expect(station.name).to eq "Kings Cross"
... | true |
2746a388ca7e2ec876ef9cb5f52e37c6e1d72f76 | Ruby | willian/validators | /lib/validators/cnpj.rb | UTF-8 | 1,074 | 2.96875 | 3 | [
"MIT"
] | permissive | module Validators
module Cnpj
extend self
def valid?(cnpj_number)
cnpj_number.gsub!(/\D+/i, "")
return false if cnpj_number.nil?
return false if cnpj_number.strip == ""
return false if cnpj_number.size != 14
return false if %W[00000000000000 11111111111111 22222222222222 333333... | true |
58fc16a3ae987202b619177f27b1229ada0e019e | Ruby | aha-app/msgraph-sdk-ruby | /lib/odata/singleton.rb | UTF-8 | 343 | 2.59375 | 3 | [
"MIT"
] | permissive | module OData
class Singleton
attr_reader :name
attr_reader :type_name
def initialize(options = {})
@name = options[:name]
@type_name = options[:type]
@service = options[:service]
end
def collection?
false
end
def type
@service.get_type_by_name(type_n... | true |
3cef1b8d5e7ea09c071ea6eab18bc3b03d7c2332 | Ruby | NatalieTapias/slack-cli | /lib/channel.rb | UTF-8 | 940 | 2.859375 | 3 | [] | no_license | require 'dotenv'
require_relative 'recipient'
Dotenv.load
module SlackCLI
class Channel < Recipient
attr_reader :slack_id, :name, :topic, :member_count
def initialize(slack_id:, name:, topic:, member_count:)
@slack_id = slack_id
@name = name
@topic = topic
@member_count = member... | true |
8c6118e619e65f3e52fb44873fff95e99b837661 | Ruby | NickQiZhu/calculator | /lib/calculator.rb | UTF-8 | 639 | 3.28125 | 3 | [
"MIT"
] | permissive | require_relative 'lex'
require_relative 'parser'
class Calculator
include Operations
def initialize
@lex = Lex.new
@parser = Parser.new
end
def calculate(exp)
evaluate(@parser.parse(@lex.tokenize(exp)))
end
private
def evaluate(node)
if operation?(node)
evaluate_operation(node)
... | true |
362453a822345920a16bf3dba20dea7f640e6977 | Ruby | mmanousos/ruby-small-problems | /oop_problems/inheritance/seven_class_lookup.rb | UTF-8 | 415 | 3.78125 | 4 | [] | no_license | # Method Lookup (Part 1)
# Using the following code, determine the lookup path used when invoking
# cat1.color. Only list the classes that were checked by Ruby when searching for
# the #color method.
#
# class Animal
# attr_reader :color
#
# def initialize(color)
# @color = color
# end
# end
#
# class Cat < A... | true |
82d627162267ef911807ca6010eaad7759b5b4c1 | Ruby | JoshuaTatterton/learn_to_program | /ch10-nothing-new/ninety_nine_bottles_of_beer.rb | UTF-8 | 2,196 | 3.90625 | 4 | [] | no_license | def english_number number
if number < 0
return "Please enter a positive number."
elsif number == 0
return "Zero"
end
num_string = ""
ones = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
teens = [ "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eight... | true |
74e75e4a2281327b2cd32cb28c81f89400a51d9e | Ruby | CharlesMassry/Metis-Prework | /learn_to_program/calc.rb | UTF-8 | 459 | 4.34375 | 4 | [] | no_license | puts 1.0 + 2.0
puts 2.0 * 3.0
puts 5.0 - 8.0
puts 9.0 / 2.0
puts 1+2
puts 2*3
puts 5-8
puts 9/2
puts "how many hours are in a year?"
puts 24 * 365
puts "how many minutes are in a decade?"
puts 60 * 24 * 365 * 10
puts "how many seconds old are you?"
puts 26.25 * 365 * 24 * 60 * 60
puts "how many chocolates do you hope... | true |
4b276f6793bbeca45ab9ba27f447d842e0f31a7e | Ruby | Bill-A/mastermind | /rspec/mastermind_spec.rb | UTF-8 | 1,994 | 3 | 3 | [] | no_license | require './mastermind'
describe 'Mastermind' do
# Red Orange Yellow Green Blue Purple
before do
allow_any_instance_of(Mastermind).to receive(:make_a_code).and_return("R,O,Y,G")
@mastermind = Mastermind.new
end
it 'alway passes this test' do
expect true
end
it 'has Code Master make a secret ... | true |
fa4b12da0d7143c8e5977c65b39ba2843d4d9317 | Ruby | mberkland/launch_school_120 | /lesson_2/classes_and_objects.rb | UTF-8 | 1,840 | 5.09375 | 5 | [] | no_license | # Exercise 1
# Given the below usage of the Person class, code the class definition.
# Exercise 2
# Modify the class definition from above to facilitate the following methods.
# Note that there is no name= setter method now.
# Exercise 3
# Now create a smart name= method that can take just a first name or a full name... | true |
829d75330bec985f08d0f935e6092ac58e91138f | Ruby | cgilchrist/createsend-ruby | /lib/createsend/segment.rb | UTF-8 | 2,331 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'createsend'
require 'json'
module CreateSend
# Represents a subscriber list segment and associated functionality.
class Segment
attr_reader :segment_id
def initialize(segment_id, api_key)
@segment_id = segment_id
@api_key = api_key
@create_send = CreateSend.new(@api_key)
end
... | true |
adbd2f879e90f2683c3da1b5ec5f6ed7a92a72bd | Ruby | kaiwensun/leetcode | /0001-0500/0392.Is Subsequence.rb | UTF-8 | 210 | 3.3125 | 3 | [] | no_license | # @param {String} s
# @param {String} t
# @return {Boolean}
def is_subsequence(s, t)
sp = 0
for c in t.each_char
sp += 1 if s[sp] == c
break if sp == s.size
end
sp == s.size
end
| true |
9976fafff9392b1136a26500464dffa9ac267637 | Ruby | sutou81/Attendance_A | /app/views/users/show.csv.ruby | UTF-8 | 551 | 2.59375 | 3 | [] | no_license | require 'csv'
bom = "\uFEFF"
CSV.generate(bom) do |csv|
column_names = %w(日付 曜日 出社時間 退社時間 在社時間)
csv << column_names
@attendances.each do |day|
a = day.approved_started_at == nil ? nil : l(day.approved_started_at, format: :time)
b = day.approved_finished_at == nil ? nil : l(day.approved_finished_a... | true |
7fd656e31a8088dc0ea16a33bbe1259f28ea9485 | Ruby | nishant-cyro/Tracks | /Ruby/Ruby18/ruby18.rb | UTF-8 | 328 | 3.6875 | 4 | [] | no_license | require_relative 'shape'
def finding_areas
shape = Shape.new
puts "Area of Circle with radius 5 unit is #{shape.area 5}"
puts "Area of Rectangle with length 5 unit and breadth 10 unit is #{shape.area 5, 10}"
puts "Area of Triangle with sides 5 unit, 10 unit and 13 unit is #{shape.area 5, 10, 13}"
end
findi... | true |
d1142bcec52c91fb6627bf328ce2bb76a98c62f8 | Ruby | Ken0721/helloruby | /penultimate.rb | UTF-8 | 847 | 3.0625 | 3 | [] | no_license | =begin
Sample code to read in test cases:
File.open(ARGV[0]).each_line do |line|
# Do something with line, ignore empty lines
# #...
# end
=end
#check if there is a argument.
if ARGV[0].nil? then
puts "Missing arguments. Usage: ruby penultimate.rb <filename>"
exit(1)
end
#check if there is the file o... | true |
e6afc21066a019b1ec8bff9ba4989e643dac1395 | Ruby | ivins/jungle-rails | /spec/models/user_spec.rb | UTF-8 | 2,334 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
subject {described_class.new(first_name: 'Stanley', last_name: 'Stone', email: 'steve@steve.com', password: 'tttttttt', password_confirmation: 'tttttttt')}
describe "Validations" do
it "validates all user fields are present" do
expect(subject... | true |
17710d3932037dc3a6ba2c989f5e932d1f8753ed | Ruby | BeatriceCharrier/test04 | /kata_06.rb | UTF-8 | 222 | 3.71875 | 4 | [] | no_license | # square every digit of a number
def square_digits(nums)
nums_array = nums.to_s.chars.map(&:to_i)
squared_array = nums_array.each.map {|num| num * num}
squared_array.join.to_i
end
puts square_digits(41)
| true |
a3c8d74240bd2e1e1054a9b1b780085b842194b2 | Ruby | carolyoon/phase-0-tracks | /ruby/nested_data_structures.rb | UTF-8 | 1,156 | 2.9375 | 3 | [] | no_license | #Multi-Purpose Fitness Center
fitness_center = {
kick_boxing: {
room_name: 'Kick Block',
equipment: ['punching bags', 'gloves', 'floor mats'],
difficulty_level_time: {
beginner: '45 minutes',
intermediate: '60 minutes',
advanced: '75 minutes'
}
},
yoga: {
room_name: 'Namastay Here',
equipment: ... | true |
5f897494af50ce4c0d38ad866034272051cfce55 | Ruby | rsnorman/julysoundcheck | /app/services/sheet_sync/worksheet.rb | UTF-8 | 2,111 | 2.53125 | 3 | [] | no_license | module SheetSync
class Worksheet
SHEET_KEY = if Rails.env.test?
ENV['TEST_GOOGLE_SHEET_KEY'].freeze
else
ENV['GOOGLE_SHEET_KEY'].freeze
end
GOOGLE_DRIVE_CREDS_FILEPATH = './config/google_drive.json'.freeze
GOOGLE_DRIVE_CREDS = {
'... | true |
a018b638b6b6edfd6e62fd2c2b44a5e274ccab83 | Ruby | tpanum/sw701e12 | /server.rb | UTF-8 | 892 | 2.53125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'json'
class SlaveServer
HOST = "172.25.21.23"
module EchoServer
def receive_data data
begin
json = JSON.parse(data)
puts echoCommand(json)
rescue JSON::ParserError
puts "Too fast Bjarke, SLOWER!"
e... | true |
33e46d94545203e70a2237f4e69ee35f8061c010 | Ruby | nvengal/freshtrak-registration-api | /app/lib/safe_random.rb | UTF-8 | 939 | 3.328125 | 3 | [] | no_license | # frozen_string_literal: true
# Generates codes of set length with limited characters
class SafeRandom
# Use only lowercase letters to make it easy for users
# entering codes on smart phones
# Exclude letters that could result in offensive codes
SAFE_ALPHABET = (('a'..'z').to_a - %w[a e i o u l v]).freeze
... | true |
6249ba444db8330e6e81ccde7c76a98f08f11527 | Ruby | KomiKomix/komi-comix | /app/models/spree/variant_decorator.rb | UTF-8 | 815 | 2.515625 | 3 | [] | no_license | Spree::Variant.class_eval do
scope :by_num_sku, -> { where('sku ~ ?', '^\d*[0-9]\d*$').order(sku: 'desc') }
# before_save :set_sku
def initialize(*args)
super(*args)
last_variant = Spree::Variant.by_num_sku.first
sku = last_variant ? last_variant.sku.to_i + 1 : 1
self.sku = sku.to_s.rjust(4, '0... | true |
61d706c1df6e4c70c9fa3d25fc14ba8d80e2a383 | Ruby | murilovmachado/project-euler | /problem_004.rb | UTF-8 | 804 | 4.15625 | 4 | [] | no_license | def getLargestPalindromeFromProductOfTwoFactors(digitsFromFactors)
maxFactor = ("9" * digitsFromFactors).to_i
palidromes = Array.new
# Optimization variables
optimizingOn = false
maxFirstFactorForPalindrome = 0
i = maxFactor
while i >= 1 and i > maxFirstFactorForPalindrome
j = i
while j >= 1
product = i... | true |
7d510c6cfada3add79f8c054e932edda631d18de | Ruby | mctaylorpants/ruby-chess | /spec/scenario_spec.rb | UTF-8 | 1,913 | 2.59375 | 3 | [] | no_license | require 'game_controller'
RSpec.describe GameController do
context 'special moves' do
let(:gc) { GameController.new }
before { gc }
it 'allows en passant' do
moves = gc.select_piece('c2')
expect(moves.keys).to include([3,3])
expect(moves.keys).to include([3,4])
end
it 'only al... | true |
b6cc72e7f1e2e4ebc8785571ef3efeb91b235588 | Ruby | openc/openc_analytics | /report.rb | UTF-8 | 3,371 | 2.5625 | 3 | [] | no_license | # Inspired by https://gist.github.com/3166610
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/file_storage'
require 'date'
require 'statsd'
API_VERSION = 'v3'
CACHED_API_FILE = "analytics-#{API_VERSION}.cache"
CREDENT... | true |
dafeaf0294bb56cab1deb3d9b5bab9f997bd2675 | Ruby | GKhalsa/headcount | /lib/enrollment.rb | UTF-8 | 895 | 3.0625 | 3 | [] | no_license | require 'pry'
require_relative 'district'
class Enrollment
attr_accessor :name, :school_data #:high_school_graduation_rates,
def initialize(enrollment_data)
@name = enrollment_data[:name]
@school_data = {kindergarten_participation: enrollment_data[:kindergarten_participation], high_school_graduation_rates... | true |
25cc53d0676a7e00b530330083baa4f2fc650061 | Ruby | oojewale/matrack | /lib/orm/data_manager.rb | UTF-8 | 1,551 | 2.671875 | 3 | [
"MIT"
] | permissive | require "sqlite3"
require "digest/sha1"
module Matrack
class DataManager
class << self
def db_conn
db = SQLite3::Database.new "#{APP_PATH}/db/app.sqlite3"
db.results_as_hash = true
db
end
def db_error(message)
DataUtility.db_error(message)
end
def ... | true |
500ef70b186ce5afedfda5458b38a17e4244825c | Ruby | edwardloveall/bestiary | /lib/bestiary/parsers/xp.rb | UTF-8 | 290 | 2.703125 | 3 | [
"LicenseRef-scancode-ogl-1.0a",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Bestiary::Parsers::Xp
def self.perform(creature)
elements = creature.css('p')
elements.each do |bold|
if bold.text.match('XP ')
xp_string = bold.text.gsub(/(XP |,)/, '')
return xp_string.to_i
end
end
raise 'could not parse XP'
end
end
| true |
1a7c9539065c70f131be8523bd305dcc594292b6 | Ruby | xdkernelx/phase-0-tracks | /ruby/driver.rb | UTF-8 | 2,901 | 2.984375 | 3 | [] | no_license | require_relative 'santa'
test = Santa.new
test.speak
test.eat_milk_and_cookies("Snickerdoodle")
p test.age
p test.ethnicity
p test.gender
santas = []
santas << Santa.new("agender", "black")
santas << Santa.new("female", "Latino")
santas << Santa.new("bigender", "white")
santas << Santa.new("male", "J... | true |
3a677fbb741ddcb5f5593f2981efca41b3575d2b | Ruby | frankliu81/ruby_fundamentals | /day6_algorithms/work1_max_in_array.rb | UTF-8 | 2,266 | 4.4375 | 4 | [] | no_license | require "benchmark"
# write a method that returns the maximum number in array in two ways
# using loop
def max_in_array_loop(arr)
max = arr[0]
arr.each do |x|
if x > max
max = x
end
end
max
end
# this is for printing the stack trace with variable number of tabs
$recursion_depth=-1
# Frank's us... | true |
46a3efa2ab334ecf94e22663f2cf5c015d4588d2 | Ruby | emilesilvis/p45-battleships-challenge | /spec/models/game_engine/board_setuper_spec.rb | UTF-8 | 1,029 | 2.5625 | 3 | [] | no_license | require 'spec_helper.rb'
describe GameEngine::BoardSetuper do
let(:path_to_game_config) { Rails.root.join("spec/assets/game_config.json") }
subject(:board_setuper) { GameEngine::BoardSetuper.new(path_to_game_config, Rails.root.join("spec/assets/ship_blueprints.json")) }
describe "#setup" do
before do
... | true |
83036b4a455890a9b47ca865eb69795bcd360384 | Ruby | larafinnegan/rg-answers | /app/models/question.rb | UTF-8 | 232 | 2.5625 | 3 | [] | no_license | class Question < ActiveRecord::Base
has_many :answers
def top_answer
top_answer = self.answers.by_votes.first
if top_answer.present?
top_answer.description
else
"Be the first to answer this question!"
end
end
end
| true |
bac8392793c899af0e2b4dac8babdc4421934368 | Ruby | Wayzyk/batting | /lib/src/performance.rb | UTF-8 | 1,723 | 2.765625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'team'
module Batting
require 'csv'
class Performance
def initialize(logger = nil)
@team = Batting::Team.new(Batting::TEAMS_FILE)
@logger = logger
end
def perform(options = {})
@options = options
results = []
buffer = ... | true |
2a5070507033042bc95ac8dae09fa49585a53d6c | Ruby | msrashid/Exercise-sets-for-101-109---Small-Problems | /adv1/ex2.rb | UTF-8 | 311 | 3.171875 | 3 | [] | no_license | def star(number)
(1..(number - 3) / 2).to_a.reverse.each_with_index { |x, i|
puts "*#{" " * x}*#{" " * x}*".center(number)}
puts "***".center(number)
puts "*" * number
puts "***".center(number)
(1..(number - 3) / 2).to_a.each_with_index { |x, i|
puts "*#{" " * x}*#{" " * x}*".center(number)}
end | true |
30829b12157d1fef4906e49f6e08c66b60bed075 | Ruby | metaslim/kogan | /lib/commands/average.rb | UTF-8 | 1,366 | 3.171875 | 3 | [] | no_license | require_relative 'base'
module Kogan
module Commands
class Average < Kogan::Commands::Base
CUBIC_WEGHT_CONVERSION_FACTOR = 250
CM3_TO_M3 = 1000000
private
def is_valid?(input)
input =~ /^average\s+?.*$/
end
def execute(client, input)
command, category = inpu... | true |
df4d0d3135ecb3046d43dc6058c5c12fa34e9a30 | Ruby | Dancalif/Learning-Ruby | /TA/HW_22/script_22_04.rb | UTF-8 | 4,324 | 2.796875 | 3 | [] | no_license |
BEGIN{
name = "Denis Umanets"
description = "Inserting data into 2 empty hashes"
puts "#################################### "
puts "Author \s\s\s\s\s : " + name
puts "Date \s\s\s\s\s\s\s\s: " + Time.now.to_s[0 .. 18]
puts ""
puts "Ruby version : " + RUBY_VERSION
puts "S... | true |
ca88a59d49411ea06c5ca6c3c2842be9ef112892 | Ruby | gracexinran/oo-tic-tac-toe-bootcamp-prep-000 | /lib/tic_tac_toe.rb | UTF-8 | 2,229 | 3.96875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class TicTacToe
def initialize()
@board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
end
WIN_COMBINATIONS = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [6, 4, 2]]
def display_board()
puts " #{@board[0]} | #{@board[1]} | #{@board[2]} "
puts "-----------"
puts " #{@b... | true |
aa3fc8818de185fac67a03a8a4ab2794f1be5d8f | Ruby | mrkmx/thinknetica | /lesson_07/passenger_carriage.rb | UTF-8 | 167 | 2.703125 | 3 | [] | no_license | require_relative 'carriage'
class PassengerCarriage < Carriage
def initialize(volume)
super(:passenger, volume)
end
def take_volume
super(1)
end
end
| true |
7a77e40fd23f053795eeb0585c319dc775c2c299 | Ruby | tk0358/math_puzzle_for_programmer_brain | /02_sisoku_enzan_javascript2ruby.ruby | UTF-8 | 680 | 3.515625 | 4 | [] | no_license | #答えられず
#javascriptの解答例を見て作る
# Rubyでは先頭が0で始まる数字は8進数として処理されるので、
# 先頭に0がある場合は除外
op = ["*", ""]
(1000..9999).each do |i|
c = i.to_s
op.size.times do |j|
op.size.times do |k|
op.size.times do |l|
val = c[0] + op[j] + c[1] + op[k] + c[2] + op[l] + c[3]
if val.size > 4
v... | true |
ff0facc6e9baa2c04bd78a84a39c2710d4518822 | Ruby | javrodri42/discovery_piscine_ruby | /ruby06/ex03/greetings_for_all.rb | UTF-8 | 223 | 3.734375 | 4 | [] | no_license | #!/usr/bin/env ruby
def greetings(word = "noble desconocida")
if word.is_a? String
puts "Hello, #{word}."
else
puts "¡Error! No es un nombre."
end
end
greetings('Lucia')
greetings()
greetings(22) | true |
9cf4472a0f6d65659cd6f3e35bcbbfa1d44d2736 | Ruby | calvinsettachatgul/hackerrank | /ruby/enumerable-collect.rb | UTF-8 | 716 | 3.84375 | 4 | [] | no_license | def convert13(string)
# your code here
alphabet = ("a".."z")
alph_array = alphabet.to_a
# p alph_array[5]
rot13_hash = {}
alph_array.each_with_index do | char , index |
rot13_hash[char] = alph_array[(index+13) % 26]
rot13_hash[char.capitalize] = rot13_hash[char].capitalize
end
result = []
... | true |
02ae660723669ffa5763cd616eafe30567d5b30e | Ruby | ymason/ironhack | /Week_03/chess_validator/lib/queen.rb | UTF-8 | 243 | 3.1875 | 3 | [
"MIT"
] | permissive | require_relative('diagonal')
require_relative('horizontal')
class Queen < Piece
include Diagonal
include Horizontal
def can_move?(ending_x, ending_y)
horizontal_move?(ending_x, ending_y) ||
diagonal_move?(ending_x, ending_y)
end
end | true |
861d8a1a79a65f504934e5ae84de4d08fb28f2f9 | Ruby | lbaehren/prometheus-sumo | /sources/tests/TestCalculation.rb | UTF-8 | 421 | 2.953125 | 3 | [] | no_license | require 'test/unit'
class TestCalculation < Test::Unit::TestCase
# Test addition of two numbers
def test_add
assert_equal( 2, 1+1 )
end
# Test substraction of two numbers
def test_sub
assert_equal( 1, 2-1 )
end
# Test multiplication of two numbers
def test_mult
assert_equal( 4, 2*2 )
e... | true |
c58c82c865d14305f8b5b58f63b72cc8489ff5bf | Ruby | Priya67/Daily_Work | /w2d3-master/poker/spec/poker_spec.rb | UTF-8 | 2,175 | 3.71875 | 4 | [] | no_license | require 'game.rb'
require 'card.rb'
require 'player.rb'
require 'deck.rb'
require 'hand.rb'
require 'rspec'
describe "game" do
subject(:game) {Game.new(["Mike", "Priya"])}
describe "#initialize" do
it "creates a new deck" do
expect(game.deck).to be_truthy
end
it "accepts an array of player name" ... | true |
d903c74523b0b1b80f6177208166d9e802dce5db | Ruby | MMercer88/Jack | /VM/VM.rb | UTF-8 | 1,233 | 2.984375 | 3 | [] | no_license | #Author: Eric Gagnon
#Date: Mar. 25, 2014
require './parser'
require './codewriter'
class VM
def initialize
@files = ARGV
@code = CodeWriter.new(@files[0])
end
def run
if @files.length > 1
@code.writeInit
end
@files.each do |file|
thisFile = IO.readlines(file).select{|s| !(s.... | true |
e765529a4c5158fb4dc74dbdb4e73efbaaa864e6 | Ruby | Vaguery/Nudge | /instructions/code/delete_nth_point.rb | UTF-8 | 416 | 2.59375 | 3 | [] | no_license | # encoding: UTF-8
class CodeDeleteNthPoint < NudgeInstruction
get 1, :code
get 1, :int
def process
tree = NudgePoint.from(code(0))
if tree.is_a?(NilPoint)
raise NudgeError::InvalidScript, "code_delete_nth_point can't parse an argument"
end
where = int(0) % tree.points
i... | true |
59468c1bbd25dc20cd1ce58f4f8dfe1b003a0e89 | Ruby | sr/merb-more | /merb-cache/lib/merb-cache/cache-store/database-datamapper.rb | UTF-8 | 2,523 | 2.515625 | 3 | [
"MIT"
] | permissive | module Merb::Cache::DatabaseStore::DataMapper
# Module that provides DataMapper support for the database backend
# The cache model
class CacheModel < DataMapper::Base
set_table_name Merb::Controller._cache.config[:table_name]
property :ckey, :string, :length => 255, :lazy => false, :key => true
prop... | true |
cbccc72ac50bc65071cd6a227535e084017b5a49 | Ruby | tzmfreedom/ruby-samples | /basic/dry.rb | UTF-8 | 241 | 2.53125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'dry-types'
require 'dry-struct'
module Types
include Dry::Types.module
end
class User < Dry::Struct
attribute :name, Types::String
attribute :age, Types::Integer
end
pp User.new(name: 'hoge', age: 35)
| true |
266568f2783f39f36fd1c0441f332ea2cd17e53f | Ruby | ClaudioRussi/memcached | /memcached_storage.rb | UTF-8 | 3,175 | 3.53125 | 4 | [] | no_license | require_relative './memcached'
require_relative './node'
# Uses a hash in order to get O(1) in searchs with the key,
# and a linked list in order to use lru when it has no space left
class MemcachedStorage
attr_reader :head_node, :tail_node, :hashed_storage, :max_bytes
def initialize(max_bytes)
@semaphore = ... | true |
3cf0d949b41bf508e2b7e9212687b402b9ce2304 | Ruby | jkone27/sonic-hi | /simpler.rb | UTF-8 | 1,356 | 2.609375 | 3 | [
"MIT"
] | permissive | Dir.chdir('C:\Users\Giacomo\Desktop')
Notes = [:a,:b,:c,:d,:e,:f,:g].ring
Possession = [
'i',
'you',
'me',
'us',
'we',
'they',
'them',
'ours',
'theirs',
'yours'
]
def mapWordToNote(word)
if (Possession).include? word.downcase then
Notes[word.length]
else
scale(:A2, [:minor].sample, nu... | true |
dd34f509845db26b33a3119b6786e4abed8d1581 | Ruby | ignacio-chiazzo/Shopify-Pagination-relative-cursor-vs-page | /src/pagination/cursor_based_paginate.rb | UTF-8 | 1,148 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../utils/string'
require_relative '../constants'
require_relative '../paginated_models'
require_relative 'paginate'
class CursorBasedPaginate < Paginate
def initialize(domain:, access_token:)
@api_version = Constants::API_VERSION_USING_CURSOR_RELATIVE
super
... | true |
9d4ec39ed243b5626bae827792318126b7e75455 | Ruby | samunt/ruby-funademntals2 | /exersise7.rb | UTF-8 | 563 | 3.671875 | 4 | [] | no_license | def stud_meth
students = {
:cohort1 => 34,
:cohort2 => 42,
:cohort3 => 22
}
#iterate over hash to put cohort: num students
students.each do |key, value|
puts "#{key}: #{value} students"
end
puts " "
students[:cohort4] = 43 #add new cohort and student number to hash
puts students.keys #show all ke... | true |
bda134505ecc5c8ee2c9e5092d38e1f98ae8ef5c | Ruby | eet-nu/pseudonymize | /test/test_psuedonymize.rb | UTF-8 | 2,134 | 3.0625 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require 'pseudonymize'
describe Pseudonymize do
describe '.pseudonymize' do
def pseudonymize(*args)
Pseudonymize.pseudonymize(*args)
end
describe 'with a name' do
it 'pseudonymizes a European name' do
pseudonymize('Tom-Eric Gerritsen', type: :name).must... | true |
9d20c4438395f3b94ddf56b92db38bb0eb56f839 | Ruby | tracykaur/morning-challenges | /09_unique.rb | UTF-8 | 455 | 3.984375 | 4 | [] | no_license | # Unique
#
# Ruby has a handy array.unique helper which removes
# duplicates. Imlpement your own version of the helper,
# without using .unique.
#
# Difficulty:
# 5/10
#
# Example:
# unique([1,2,3,3]) should return [1,2,3]
# unique(["tom", "tom", "tom"]) should return ["tom"]
#
# Hints:
# A hash could be helpful in you... | true |
45be682a3685f498de368f02de7405d470d53be5 | Ruby | yhuang/trueandco | /bra_size_adjuster.rb | UTF-8 | 728 | 3.1875 | 3 | [] | no_license | require_relative 'band_size'
require_relative 'cup_size'
class BraSizeAdjuster
def initialize(size)
match_data = size.match /(\d+)([A-Z]+)/
@band_size = BandSize.new match_data[1]
@cup_size = CupSize.new match_data[2]
end
def adjust(type, direction)
case type
when :band
apply_band... | true |
45b54fa2126c9fbe55a2a741642d3077081d0cc2 | Ruby | algorithm-archivists/algorithm-archivists.github.io | /contents/verlet_integration/code/ruby/verlet.rb | UTF-8 | 781 | 3.140625 | 3 | [
"MIT"
] | permissive | def verlet(pos, acc, dt)
prev_pos = pos
time = 0
while pos > 0 do
time += dt
temp_pos = pos
pos = pos*2 - prev_pos + acc * dt * dt
prev_pos = temp_pos
end
return time
end
def stormer_verlet(pos, acc, dt)
prev_pos = pos
vel = 0
time = 0
while pos > ... | true |
f183d81382af9a79907d02accc3fa23d09d1e761 | Ruby | kripy/coudal-with-pictures | /app.rb | UTF-8 | 2,763 | 2.765625 | 3 | [
"MIT"
] | permissive | require "sinatra/base"
require "nokogiri"
require "httparty"
require "aws-sdk"
require "rss"
require "uri"
class App < Sinatra::Base
configure do
set :root, File.dirname(__FILE__)
end
helpers do
def get_url_from_description(str_text)
# puts str_text
str_text = URI.extract(str_text.inner_text... | true |
8e834940a79351ba53d3dd18beffbf2b11562219 | Ruby | pathbox/Working-With-TCP-Sockets | /connect.rb | UTF-8 | 272 | 2.8125 | 3 | [] | no_license | require 'socket'
socket = Socket.new(:INET, :STREAM)
remote_addr = Socket.pack_sockaddr_in(80, 'hao123.com')
socket.connect(remote_addr)
# Again, since we're using the low-level primitives here we're needing to pack the address object into its C struct representation. | true |
1c4852f4055d9a3492a6eaf0d8efc6e02d75559f | Ruby | Cosmin-Croitoriu/oystercard | /spec/station_spec.rb | UTF-8 | 352 | 2.8125 | 3 | [] | no_license | require 'station'
describe Station do
it 'should return the zone of a station' do
station = Station.new('Liverpool Street', 1)
expect(station.zone).to eq(1)
end
it 'should return the name of the station' do
station = Station.new('Liverpool Street', 1)
expect(station.name).to eq... | true |
6009caa2ebf390665e8d1a7fde677dc212f44427 | Ruby | carlmcateer/lrthw | /ex15.rb | UTF-8 | 829 | 4.1875 | 4 | [] | no_license | # This line declares a variable to be the first argument entered when the file is opened.
#filename = ARGV.first
# This line declaret the variabe text to be equal to the contence of the file that the var file name is equal to
#txt = open(filename)
# Puts the string below into the terminal and the name of the file tha... | true |
0f5ae7964074ef7f73b469510ad6357f94c70bb8 | Ruby | bwbirdsall/title_case | /lib/titlecase.rb | UTF-8 | 528 | 3.53125 | 4 | [] | no_license | def titlecase(string)
title_array = string.split(" ")
title_result = []
result = ""
exceptions = ['of', 'as', 'the', 'with', 'and', 'but', 'or', 'a', 'an', 'from', 'without', 'for', 'until', 'so', 'yet', 'because']
title_array.each do |word|
if exceptions.index(word) != nil
if title_array.index(wor... | true |
63f0462482e81a28289a75d7cb09f40fd6e37fd5 | Ruby | angusjfw/takeaway-challenge | /spec/takeaway_spec.rb | UTF-8 | 1,399 | 2.921875 | 3 | [] | no_license | require 'takeaway'
describe Takeaway do
let(:order) do
double :order, as_hash: {'Spring Rolls' => 2, 'Crispy Duck' => 1},
total: 12.97
end
let(:order_klass) { double :order_klass, new: order }
let(:carrot_order) { double :order, as_hash: {'Carrot' => 99} }
let(:carrot_order_klass) { double :order... | true |
4c87415e51945dd5d269f5b6b1b606f9168a6cbc | Ruby | egtaonline/rmarket | /lib/rmarket/beliefs/news.rb | UTF-8 | 1,416 | 2.84375 | 3 | [
"MIT"
] | permissive | module RMarket
module Beliefs
# Piece of news patterned after Epstein-Schneider 2008
class News
attr_reader :signal, :previous_dividend
def initialize(signal, previous_dividend=nil)
@signal = signal
@previous_dividend = previous_dividend
end
end
# noise in news pe... | true |
135476d2142c541b883f2cd73209cae3a9d85c0e | Ruby | jordanbrauner/curriculum | /04-ruby-mvc-sinatra/object_oriented_programming_in_ruby/examples/collaborator_squad_and_person.rb | UTF-8 | 567 | 4.09375 | 4 | [] | no_license | class Person
attr_reader :name
def initialize(name)
@name = name
end
end
class Squad
def initialize(name)
@name = name
@students = []
end
def students
return @students
end
def add_student(student)
@students.push(student)
end
end
walter = Person.new("Walter")
robert = Person.new... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.