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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9715cce807350cc16529b9d3b9cc2c5a06931697 | Ruby | louischavane/Climb_MVC | /router.rb | UTF-8 | 544 | 3.375 | 3 | [] | no_license | require_relative "controller"
class Router
def initialize
@controller = Controller.new
end
def start
loop do
# ask action
puts "Que veux-tu faire ? "
puts "1 - Lister les voies"
puts "2 - Ajouter une voie"
puts "3 - Déclarer une voie grimpée"
action = gets.chomp
... | true |
7ea979089c9399f6e6d9b7c5b4e0dcebacdf8e64 | Ruby | brennanholtzclaw/enigma | /lib/key_generator.rb | UTF-8 | 463 | 3.21875 | 3 | [] | no_license | require 'pry'
require 'date'
class KeyGenerator
attr_reader :key, :date, :a_rotation, :b_rotation, :c_rotation, :d_rotation
def initialize(key = rand(99999))
@key = key.to_s
key_checker(@key)
@a_rotation = @key[0..1]
@b_rotation = @key[1..2]
@c_rotation = @key[2..3]
@d_rotation = @key[3..4... | true |
af15370a820f7d8d33ac2098413056f42a0670da | Ruby | suhy-jang/morning-code | /leetcode/42.longest-increasing-subsequence/suhy.rb | UTF-8 | 404 | 2.96875 | 3 | [] | no_license | # @param {Integer[]} nums
# @return {Integer}
def length_of_lis(nums)
return 0 if nums.size.zero?
dp = Array.new(nums.size, 0)
dp[0] = 1
maxans = 1
nums.each_with_index do |num, i|
maxval = 0
0.upto(i-1) do |j|
maxval = [maxval, dp[j]].max if nums[j] < num
end
... | true |
1ad7b43aab8f9f847f9f0a03387f294900c917e4 | Ruby | henshiru/maeve | /lib/matrix_util.rb | UTF-8 | 135 | 2.625 | 3 | [
"MIT"
] | permissive | require 'matrix'
class Vector
def []=(i,x)
@elements[i] = x
end
end
class Matrix
def []=(i,j,x)
@rows[i][j]=x
end
end | true |
bb7c1ae5bf3daf725d373cee62bd01be13749a6a | Ruby | kellyselden/random_word_search | /lib/cell.rb | UTF-8 | 233 | 3.421875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-wordnet",
"LicenseRef-scancode-other-permissive",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-mit-old-style"
] | permissive | class Cell
def initialize x, y, capacity
@x = x
@y = y
@capacity = capacity
@chr = nil
@words = Array.new
end
def full?
@words.length == @capacity
end
def to_s
@chr || "_"
end
attr_accessor :chr, :words
end
| true |
9cadb8c3ee3139b2453ce7f2ddade4629d89e322 | Ruby | cheyang/docker_brick | /lib/brick/cli.rb | UTF-8 | 6,568 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'mixlib/cli'
require 'brick/application'
require 'brick/monkey_patches/cli'
module Brick
class CLI
extend Brick::Mixin::ConvertToClassName
include Mixlib::CLI
#include Application
def self.logger
@@logger ||= Logger.new(STDOUT)
@@logger.level = Logger::I... | true |
93b7d9c7d1216943c3f3007fca8f07c7b5917168 | Ruby | ixnp/deli-counter-teacher-onboarding | /deli_counter.rb | UTF-8 | 613 | 4.09375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def now_serving(arr)
if arr.length == 0
puts "There is nobody waiting to be served!"
else
puts "Currently serving " + arr[0]+"."
arr.shift
end
end
def take_a_number(arr,str)
arr.push(str)
num = arr.length
puts "Welcome, #{str}. You are number #{num} in line."
end
... | true |
46a6aaf2f6a8240a14fbbbe34d512a7de267c952 | Ruby | etdev/algorithms | /0_code_wars/difference_between_biggest.rb | UTF-8 | 259 | 2.921875 | 3 | [
"MIT"
] | permissive | # http://www.codewars.com/kata/55e3f27d5dee52d8dd0000a9
# --- iteration 1 ---
def diff_big_2(arr)
arr.slice!(arr.index(arr.max)) - arr.slice!(arr.index(arr.max))
end
# --- iteration 2 ---
def diff_big_2(arr)
arr.slice!(arr.index(arr.max)) - arr.max
end
| true |
1b9057ba370bf8249ffd8650af602895e77a150e | Ruby | jarmo/duplicati-rb | /lib/duplicati.rb | UTF-8 | 2,844 | 2.546875 | 3 | [
"MIT"
] | permissive | require File.expand_path("duplicati/version", File.dirname(__FILE__))
require File.expand_path("duplicati/command", File.dirname(__FILE__))
require File.expand_path("duplicati/backup", File.dirname(__FILE__))
require File.expand_path("duplicati/clean", File.dirname(__FILE__))
require File.expand_path("duplicati/notific... | true |
d3a20814c80c2c1559025883f4f364695788812e | Ruby | twlevelup/driver-illuminaty | /spec/taxi_spec.rb | UTF-8 | 5,265 | 3.34375 | 3 | [] | no_license | require "taxi"
describe Taxi do
it 'move one position to north' do
current_taxi = Taxi.new 1, 1,"N" #arrange
current_taxi.move
expect(current_taxi.x).to eq(1)
expect(current_taxi.y).to eq(2)
expect(current_taxi.direction).to eq('N')
end
it 'move one position to south'... | true |
56dbb9df08de2e770e8748186d88a3434911fd1a | Ruby | acmfi/AdventCode | /2017/day03/foldr/part2.rb | UTF-8 | 2,045 | 3.375 | 3 | [] | no_license | class C
attr_reader :x, :y
def initialize(x,y)
@x = x
@y = y
end
def self.[](x,y)
C.new x,y
end
def ==(o)
x == o.x and y == o.y
end
alias eql? ==
def next
return C[1,0] if x == 0 and y == 0
return C[x+1, y] if (x == y and x < 0) or (-x == y and y < 0)
retur... | true |
9255e9d655a0f8712240cf89658aa1efd897cd30 | Ruby | Ehugo2000/ruby_exercises_repo | /arrays.rb | UTF-8 | 1,441 | 3.828125 | 4 | [] | no_license | #------------ Include in array--------------
#arr = [1,3,5,7,9,11]
#number = 3
#if arr.include?number
# puts true
#else
# puts false
#end
#------------------return element in array -----------------
# arr =[["test", "hello", "world"], ["exampel", "mem"]]
# find = arr[1][0]
# puts find
#---------------differ... | true |
78f898199c40c1d887335f8168c8874072ab3d99 | Ruby | jtrtj/dark_hub | /app/models/git_hub_user.rb | UTF-8 | 313 | 2.609375 | 3 | [] | no_license | class GitHubUser
attr_reader :name, :avatar_url, :followers, :following
def initialize(attributes_json_data)
@name = attributes_json_data[:name]
@avatar_url= attributes_json_data[:avatar_url]
@followers = attributes_json_data[:followers]
@following = attributes_json_data[:following]
end
end | true |
1d11b00d625f41143fcaa9e608d2fc7607141229 | Ruby | Seluxit/hap_client | /lib/hap_client/encryption_request.rb | UTF-8 | 2,117 | 2.71875 | 3 | [
"MIT"
] | permissive | module HAP
module EncryptionRequest
AAD_LENGTH_BYTES = 2
AUTHENTICATE_TAG_LENGTH_BYTES = 16
attr_reader :encryption_count, :decryption_count
def encryption_ready?()
return !@controller_to_accessory_key.nil?
end
private
def encrypt(data)
@encryption_count ||= 0
data.c... | true |
4e5b241de839465b75a4bbe49c2951945b222e6f | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/filtered-submissions/2eb96f0a353d474f9f7b0cb14b03275c.rb | UTF-8 | 107 | 2.75 | 3 | [] | no_license | def compute(s1, s2)
0.upto([s1.size, s2.size].min).count do |i|
s1[i] != s2[i]
end
end | true |
423a3eab922ee6ff0aa4fd460a6da68523ae555c | Ruby | ncaudill27/ruby-enumerables-cartoon-collections-lab-online-web-prework | /cartoon_collections.rb | UTF-8 | 429 | 3.328125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(dwarves)
dwarves.each_with_index{ |dwarf, i| print i+1, dwarf.capitalize }
end
def summon_captain_planet(summoners)
summoners.collect{ |element| "#{element.capitalize}!" }
end
def long_planeteer_calls(calls)
calls.any?{ |call| call.size > 4 }
end
def find_the_cheese(stuff)
cheese_types ... | true |
fa8df40dec3c0b7c6599bf6fef759d5097ec7861 | Ruby | crispyb0i/clock_angle | /spec/clock_angle_spec.rb | UTF-8 | 578 | 2.953125 | 3 | [] | no_license | require('rspec')
require('clock_angle')
describe('String#clock_angle') do
it('does not accept value out of clock range') do
expect("14:63".clock_angle()).to(eq(nil))
end
it('return angle for 12 Oclock time') do
expect("12:00".clock_angle()).to(eq(0))
end
it('return angle for inputted time ') do
e... | true |
d85dd19b9828b5517ca9cad51bfcc919bbcd9033 | Ruby | Lanaed/snippets | /Ruby/active_record_todos/todo.rb | UTF-8 | 594 | 2.6875 | 3 | [] | no_license | require_relative 'config/application'
#puts "Put your application code in #{File.expand_path(__FILE__)}"
length_of_input = ARGV.length
decision = ARGV[0]
ARGV.shift
task = ARGV.join(" ")
current_length = Task.all.count
case decision
when "add"
Task.add(task)
puts "Added Task: #{task}"
when "delete"
... | true |
9a3e2718dd4ffa3f61ff825a8fff2c1a82e28cad | Ruby | minnonong/Codecademy_Ruby | /03. Control Flow in Ruby/03_15.rb | UTF-8 | 50 | 2.546875 | 3 | [] | no_license | # 03_15 Unless
a = false
print "Hello" unless a
| true |
e51a4990bf7e6ea9d926a66a82b698d8f027bed1 | Ruby | deevis/ingreedy | /lib/ingreedy/rationalizer.rb | UTF-8 | 1,034 | 3.296875 | 3 | [] | no_license | module Ingreedy
class Rationalizer
def self.rationalize(options)
new(options).rationalize
end
def initialize(options)
@integer = options.fetch(:integer, nil)
@float = options.fetch(:float, nil)
@fraction = options.fetch(:fraction, nil)
@word = options.fetch(:word, ni... | true |
80de99777b41232ab82cb01985ac5e64d242afa3 | Ruby | dubeboy/classFinderWeb | /lib/tasks/ree.rb | UTF-8 | 4,610 | 3.359375 | 3 | [] | no_license | require 'csv'
require 'time'
class Ree
@@data = CSV.read("Extraction.csv", { encoding: "UTF-8", headers: true, header_converters: :symbol, converters: :all})
@@venue_hashes = data.map { |d| d.to_hash }
# day can be 1=mon 2=tue 3=wed 4=thurs 5=fri
def self.convert_time_to_code(time, day)
if time > 800 and tim... | true |
3fb93a6d5b57284edcc8ce81b4c762c88e68bb22 | Ruby | kkamil/ruby-opentsdb | /lib/opentsdb/client.rb | UTF-8 | 1,382 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'socket'
require 'opentsdb/logging'
require 'net/http'
module OpenTSDB
class Client
include Logging
attr_reader :connection
def initialize(options = {})
begin
@hostname = options[:hostname] || 'localhost'
@port = options[:port] || 4242
@connection = TCPSocket.new(@... | true |
5d6c1fd826033a1ae6e4c45bb664a593a3a27807 | Ruby | lime1024/rubybook | /chapter_04/4-1-1.rb | UTF-8 | 158 | 2.609375 | 3 | [] | no_license | # 要素が "コーヒー" と "カフェラテ" である配列を作って p メソッドで表示する
drinks = %w[コーヒー カフェラテ]
p drinks
| true |
aef871cbe41cde851a0cf63b2cb98835ccdfe7e4 | Ruby | 5minlab/translate-yaml-generator | /lib/translate_yaml_generator/core.rb | UTF-8 | 2,477 | 3 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # encoding: utf-8
module TranslateYamlGenerator
class Record
INDEX_NAMESPACE = 0
INDEX_NAME = 1
METADATA_FIELD_COUNT = 2
def initialize(row)
raise ArgumentError.new("No language data inside row") if row.length < METADATA_FIELD_COUNT
@row = row
end
def namespace
@row[INDEX_... | true |
49b55774568769a510e22eb35e1a5f2ddb98d4c7 | Ruby | AndreeaGrt/tema | /todo_list.rb | UTF-8 | 1,074 | 3.25 | 3 | [] | no_license |
class TodoItem
attr_accessor :state
attr_accessor :description
def initialize(w, t =false)
@state = t
@description = w
end
def done?
@state
end
def done!
@state = true
end
end
class TodoList
attr_accessor :name ,:color ,:position ,:items
attr_accessor :items_pending, :items_done
def initialize(... | true |
048157cc2f8e0c1534278bdb8579f604b830d6eb | Ruby | ANamelessBand/Liberta | /app/models/copy.rb | UTF-8 | 428 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
class Copy < ApplicationRecord
has_many :loans, -> { order("time_loaned DESC") }, dependent: :destroy
belongs_to :print
validates_presence_of :print_id
validates :inventory_number, presence: true, numericality: true
def taken?
loans.any? &:unreturned?
end
def free?
... | true |
e31680862ec8cacccb10b05b65ea79ffd768be26 | Ruby | rickenharp/csv_example | /app/models/csv_export_service.rb | UTF-8 | 656 | 2.828125 | 3 | [] | no_license | require 'csv'
class CSVExportService
def initialize(exportable, wanted_fields = [])
@exportable = exportable
@wanted_fields = wanted_fields
end
def call
CSV.generate(:col_sep => "\t") do |csv|
csv << header
@exportable.to_a.each do |item|
csv << map_object_to_array(item)
e... | true |
d4faa71b0635a8a8f8e44fa8cc5c86759d0bd558 | Ruby | kkashuda/flatiron-store-project-v-000 | /app/models/item.rb | UTF-8 | 275 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain",
"MIT"
] | permissive | require 'pry'
class Item < ActiveRecord::Base
has_many :line_items
belongs_to :category
def update_inventory(li)
self.inventory = self.inventory - li.quantity
self.save
end
def self.available_items
all.select {|item| item.inventory > 0}
end
end
| true |
e0bf761506b07ec4ba0887703029b5407f163e3e | Ruby | caruby/scat | /lib/scat/authorization.rb | UTF-8 | 3,274 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'sinatra/authorization'
module Scat
module Authorization
include Sinatra::Authorization
# Runs the given block in an HTTP basic authorization context.
# The session status is set to the result of performing the given block.
#
# @yield perform the caTissue operation and return a status mes... | true |
7ad3c470f1c32f9118b8311a35fa16443c3ce746 | Ruby | zhupeijun/Algorithm | /project_euler/017.rb | UTF-8 | 960 | 3.765625 | 4 | [] | no_license | def to_str(x)
a = [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
"thirty",
"forty",... | true |
8692272a898a1728eb3f77cbe22f4de2ca721f53 | Ruby | masacheung/Adjacent-Sum | /main.rb | UTF-8 | 570 | 4.28125 | 4 | [] | no_license | # Soluation 1
def adjacent_sum(arr)
ans = []
count = 0
while count + 1< arr.length
ans << arr[count] + arr[count + 1]
count +=1
end
return ans
end
# Soluation 2
# def adjacent_sum(arr)
# new_arr = []
# arr.each.with_index do |num, idx|
# if idx != arr.length - 1
# new_arr << arr[... | true |
e0e22d213232129d1639c88496ac4ae95f34a79b | Ruby | ParrotFx/Parrot.Ruby | /Nodes/encoded_output.rb | UTF-8 | 272 | 2.609375 | 3 | [
"MIT"
] | permissive | class EncodedOutput < StringLiteral
def variable_name
return @variable_name
end
def variable_name=variable_name
@variable_name = variable_name
end
def initialize(variable_name, tail = nil)
super('"@' + variable_name + '"', tail)
end
end | true |
117040efab960f6381e8f8162fd3b400f2bb245f | Ruby | nstory/boston_public_records | /lib/line.rb | UTF-8 | 559 | 2.84375 | 3 | [
"MIT"
] | permissive | class Line
RE = / {3,}/
attr_reader :line
def initialize(line)
@line = line
end
def field_count
offsets.count + 1
end
def offsets
return [] unless /[^\s]/.match(line)
last_offset = $~.offset(0).first
a = []
loop do
md = RE.match(@line, last_offset)
break unless md
... | true |
5bc31f7bbfb65631c3fd709c77132914567d3047 | Ruby | adamjmurray/mtk | /lib/mtk/core/pitch_class.rb | UTF-8 | 6,980 | 3.5625 | 4 | [
"BSD-3-Clause"
] | permissive | module MTK
module Core
# A set of all pitches that are an integer number of octaves apart.
# A {Pitch} has the same PitchClass as the pitches one or more octaves away.
# @see https://en.wikipedia.org/wiki/Pitch_class
# @see Lang::PitchClasses
class PitchClass
# The preferred names of the 1... | true |
15e8932ccac5c4c0ebb048de82f695e756b286ac | Ruby | danott/advent-of-code-2017 | /lib/day_24.rb | UTF-8 | 2,540 | 3.234375 | 3 | [] | no_license | require "minitest"
require "minitest/autorun"
require "pry"
require "awesome_print"
TEST_INPUT = File.read("lib/day_24_test_input.txt")
PUZZLE_INPUT = File.read("lib/day_24_puzzle_input.txt")
class TheTest < Minitest::Test
def test_part_1
test_ports = Port.parse_all(TEST_INPUT.lines)
assert_equal 31, strong... | true |
a692dad7f56d4347f582f34932d902c481fc4268 | Ruby | atalanda/atalogics_api | /lib/atalogics_api/v3/client.rb | UTF-8 | 2,560 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module AtalogicsApi
module V3
# Base class for all requests to atalogics
#
# @author Hubert Hoelzl
# @attr_reader [AtalogicsApi::Auth] auth The currently used auth instance
class Client < ClientBase
private def set_base_uri
self.class.base_uri(Atalogics... | true |
f7e046d612e5a9e136c6f54c028c827a07edc6aa | Ruby | javkhlantugs/Ironhack | /week2/day3/more_sinatra/spec/todolist_spec.rb | UTF-8 | 375 | 2.515625 | 3 | [] | no_license | require_relative("../lib/todolist.rb")
require_relative("../lib/task.rb")
RSpec.describe TodoList do
describe "add a task" do
before :each do
@list = TodoList.
end
it "add a task to method" do
expect(@list.add_task(tsk = Task.new("do sth"))).to eq ([tsk])
end
it "returns task corresponding the Id" d... | true |
f0036ab17c72212c36a92cface1a291a5696b935 | Ruby | marcgg/whats-my-airport | /spec/lib/trigram_spec.rb | UTF-8 | 1,658 | 3.078125 | 3 | [] | no_license | # encoding: utf-8
require "spec_helper"
describe Trigram do
describe "regular_algorithm" do
it "should return a trigram given all data needed" do
Trigram.generate("Marc Gabriel Gauthier").should == "MGG"
end
describe "complex cases" do
it "should work when given incomplete data" do
... | true |
2a006fe44f258a2570ff497ef30067c3c84637b1 | Ruby | josediaz16/movies_api | /lib/errors/dry_result.rb | UTF-8 | 1,286 | 2.640625 | 3 | [] | no_license | module Errors
GetRealField = -> field, subfield do
case subfield
when Integer
"#{field}[#{subfield}]"
when Symbol
[field, subfield].join(".")
end.to_s
end.curry
GetCodeAndMessage = -> str do
str.first.split("~").map(&:strip).map(&:to_s)
end
class DryResult
attr_reader :r... | true |
0ef4d21e718a291751150bdfb5cc2963c41b0ae4 | Ruby | orenyomtov/ironbee | /predicate/reference_index.rb | UTF-8 | 478 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
if ARGV.empty?
puts "Usage #{$0} <file>"
exit 1
end
path = ARGV[0]
base = File.basename(path, ".adoc")
terms = []
section = nil
IO::foreach(path) do |line|
if line =~ /\[\[s.(.+)\]\]/
section = $1
elsif line =~ /\[\[p.(.+)\]\]/
terms << [$1, section]
end
end
File.open("#{base}_in... | true |
2e02080fbdf807a7068cb3b810d758712d572e29 | Ruby | sarahrosy/ruby-challenges | /always_three.rb | UTF-8 | 225 | 3.28125 | 3 | [] | no_license | def always_three(num)
print "When you take a #{num}, add 5, multiply by 2, subtract 4, and divide by 2, "
num = ((((num + 5) *2) -4) /2)- num
puts "the result is (drumroll please...) #{num}!"
end
always_three(4)
| true |
bcd159abc429827de7c40839caecbe87243423e5 | Ruby | rlogwood/rails_templates | /examples/active_record_associations/dog_cat_sti_test/template.rb | UTF-8 | 3,431 | 2.8125 | 3 | [] | no_license | # frozen_string_literal: true
# This is a simple Single Table Inheritance (STI) example
# This template was inspired by
# Single Table Inheritance in Rails 6; Emulating OOP principles in relational databases
# Gene H Fang Nov, 13, 2019
# https://medium.com/@ghl234/single-table-inheritance-in-rails-6-emulating-oop-prin... | true |
132d48a5dbbcaf83d25ad70ffc88bcdff71dec47 | Ruby | braintreeps/hydra | /lib/hydra/trace.rb | UTF-8 | 786 | 2.8125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Hydra #:nodoc:
# Trace output when in verbose mode.
module Trace
module ClassMethods
# Make a class traceable. Takes one parameter,
# which is the prefix for the trace to identify this class
def traceable(prefix = self.class.to_s)
include Hydra::Trace::InstanceMethods
cl... | true |
20c38f1c5bd122fd747f54d461958d932b99a222 | Ruby | gomezmontoya/ttt-5-move-rb-v-000 | /lib/move.rb | UTF-8 | 662 | 4.125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
# code your input_to_index/ convert string to integer value/ convert to the index of the board
d... | true |
b3ff763402271f4af90e9691cae738c1850799ee | Ruby | khriskempis/ls_ruby_exercises | /exercises/6.rb | UTF-8 | 118 | 3.15625 | 3 | [] | no_license | array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
array.push(3)
p array
unique_array = array.uniq
p unique_array
p array | true |
007f2351755634234fa088e4096f535b0bc145d6 | Ruby | floatbox/eap-ota | /test/performance/fetch_nested_test.rb | UTF-8 | 746 | 2.75 | 3 | [] | no_license | #require File.expand_path('../../config/environment', __FILE__)
require './lib/fetch_nested'
require 'benchmark'
n = 200_000
hash = {"foo" => {"bar" => {"baz" => 1}}}
puts "fetching existing key"
Benchmark.bm do |x|
x.report('normal access ') { n.times { hash["foo"]["bar"]["baz"] } }
x.report('fetch nested ... | true |
536a94799bbb058f19f4362d1f295a66a49c0d46 | Ruby | aldavidson/customer-records | /spec/lib/distance_calculator_spec.rb | UTF-8 | 2,278 | 3.015625 | 3 | [] | no_license | require 'spec_helper'
require 'lib/distance_calculator'
require 'model/location'
describe DistanceCalculator do
describe '#to_rvincenty_location' do
context 'given a Location' do
let(:location) { Location.new(latitude: 123, longitude: 456) }
it 'returns an array' do
expect(described_class.... | true |
c3f30ea98e3862c35564b8d392010ce2560043da | Ruby | VimleshS/ruby_beyond_basic | /meta_programming.rb | UTF-8 | 2,781 | 3.875 | 4 | [] | no_license | require "./data"
require "pry-byebug"
# From http://ruby-doc.org/core-2.4.1/Module.html#method-i-define_method
# Defines an instance method in the receiver. The method parameter can be a Proc, a Method or an UnboundMethod object.
# If a block is specified, it is used as the method body. This block is evaluated using i... | true |
caf31db6b003d3af79825aaaed90c8db6285dc82 | Ruby | kathyvs/Pennsic-Form-Filler | /spec/models/account_spec.rb | UTF-8 | 5,739 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Account do
describe "fetch by username and password" do
fixtures :accounts
[:admin, :pennsic, :war_practice, :clerk, :senior, :herald].each do |a|
it "should be able to login #{a} with correct password" do
expected_account = accounts(a)
account = Acco... | true |
0a29db740263251571137de5b908e608ff94c6b4 | Ruby | TENsaga/rails_learning_tweaked | /spec/model/users_spec.rb | UTF-8 | 3,122 | 2.578125 | 3 | [
"Beerware",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # spec/models/users_spec.rb
require 'rails_helper'
describe User do
it 'has a valid factory' do
expect(FactoryGirl.create(:user)).to be_valid
end
it 'is invalid without name' do
expect(FactoryGirl.build(:user, name: nil)).to_not be_valid
end
it 'is invalid wihtout email' do
expect(FactoryGirl.b... | true |
b48956232787e7e13a78c65ce1d11e2cd4d4255f | Ruby | cielavenir/procon | /euler/tyama_euler243.rb | UTF-8 | 402 | 2.609375 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
#based on http://freelancersunite.net/project_euler/project-euler-problem-243/
require 'prime'
class Integer
def totient() self.prime_division.reduce(1){|s,e|s*(e[0]-1)*e[0]**(e[1]-1)} end
end
g=Prime::EratosthenesGenerator.new
n=g.next*g.next*g.next*g.next*g.next
loop{
a=g.next
1.step(a-1){|i|
d=n... | true |
83732d14044122b43b8a121b9fc7923268e3e6f6 | Ruby | panickat/CodeaCampRuby | /sem2/dia2/5_clasepeople.rb | UTF-8 | 493 | 4.03125 | 4 | [] | no_license | #Crea la clase People que permita crear tres objetos People con diferentes nombres. Haz pasar las pruebas correspondientes.
class People
def initialize(name)
@name = name
end
def speak
"#{@name} is talking to you..."
end
end
people_1 = People.new("Rodrigo")
people_2 = People.new("Carlos")
people_3 = People.... | true |
ad4d95c77d4093b5ee8cb2a21a9af5f6d72a8bf7 | Ruby | takatoshiH/AtCoder | /ABC/ABC079B.rb | UTF-8 | 123 | 3.4375 | 3 | [] | no_license | n = gets.to_i
array = [2,1]
(2..n).each do |number|
array.push(array[number-1] + array[number -2])
end
puts array.last
| true |
510ee8ec74459535bbf517cacf21046d09c8206a | Ruby | dmullek/dominion | /app/cards/counting_house.rb | UTF-8 | 1,263 | 2.609375 | 3 | [] | no_license | class CountingHouse < Card
def starting_count(game)
10
end
def cost(game, turn)
{
coin: 5
}
end
def type
[:action]
end
def play(game, clone=false)
@play_thread = Thread.new {
ActiveRecord::Base.connection_pool.with_connection do
LogUpdater.new(game).look(game.cu... | true |
7f14ff44841f4d68527fa6681e2529ac47912eab | Ruby | michaelsmith19951/LRTHW | /exercise10/ex10.rb | UTF-8 | 663 | 4 | 4 | [] | no_license | # Set the variable called "tabby_cat" equal to a line of text that is indented
tabby_cat = "\tI'm tabbed in."
# Set the variable called "persian_cat" equal to a line of text that is placed onto two lines
persian_cat = "I'm split\non a line."
# Set the variable called "backslash_cat" equal to a line of text that convert... | true |
645a090897fb8141d7b814b03bb7f3915e3821a0 | Ruby | shirleyz9402/my-select-prework | /lib/my_select.rb | UTF-8 | 154 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(array)
i = 0
arr = []
while i < array.size
if yield(array[i]) == true
arr.push(array[i])
end
i+=1
end
arr
end | true |
36208b03dc3d33f514b4061bba27dd7f457482db | Ruby | madhu-patidar/training | /ruby/dowhile.rb | UTF-8 | 70 | 2.65625 | 3 | [] | no_license | !#/usr/bin/ruby
a = 1
b = 10
begin
puts a
a += 1
end while a == b | true |
176d3bc4781d1b0e169e873286b7a578fc8d4351 | Ruby | StevenGerdes/ECE421-project-2 | /r_shell.rb | UTF-8 | 805 | 3.09375 | 3 | [] | no_license | require 'timer'
class RShell
# attr_reader working_directory
def initialize
run
end
#Run command starts R_Shell, looping infinitely for input until the eit command is given.
def run
input = nil
loop do
begin
print '>'
input = gets.strip.split('|')
if( input.to_s == 'exit' )
return
... | true |
b27a6cd441d8a1c1feb0b7a7bda3ac4702630213 | Ruby | bluespan/green | /app/models/sales_tax_rate.rb | UTF-8 | 643 | 2.625 | 3 | [] | no_license | class SalesTaxRate < ActiveRecord::Base
class << self
@@sales_tax_rates ||= {}
def [](state)
SalesTaxRate.find_by_state(state)
end
def []= (state, rate)
SalesTaxRate.find_by_state(state).update_attributes({:rate => rate})
end
def all_states
SalesTaxRate.find... | true |
bc531a145b1a8365dfd7778944504222314c4d6b | Ruby | sydwer/dictionaries-linguage | /db/seeds.rb | UTF-8 | 9,779 | 2.6875 | 3 | [] | no_license | Word.destroy_all
Language.destroy_all
Dictionary.destroy_all
DictionaryEntry.destroy_all
nouns_english = ["Apple","Bear","Book", "Cat", "Dinner", "Fish",
"Hello", "House","Hunger", "River","Rock", "Ten","Tree"];
pronouns_english = ["I", "You","(Formal) You", "He", "She", "It", "We", "(Plural) You",
"Them", "(Masculin... | true |
c85782358d95f62731b95748769f3b2eeb3428c8 | Ruby | Kaamio/Mastermind_ruby | /mastermind.rb | UTF-8 | 3,248 | 3.828125 | 4 | [] | no_license | class Board
def initialize(puzzle)
@puzzle=puzzle
@quessinstances = []
@victory = false
@counter = 1
end
def oneround(instanssi)
quesses = []
puts "You have quessed: #{instanssi} It matches as follows: (2=correct color, correct place, 1=correct color,wrong place"
for i in 0...instanssi.length
... | true |
89272fd1f998a706ce1f2fc835206e05115db519 | Ruby | VegetableProphet/procanizer | /lib/procanizer.rb | UTF-8 | 996 | 3.03125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Procanizer
def add_proc_for(*meths)
meths.each do |meth|
define_proc_for_instance_method(meth)
set_proc_privacy_level(meth)
end
end
# uses inst variable to prevent memory bloat in some iterations
def define_proc_for_instance_method(meth)
define_meth... | true |
779db4dc8d50c866e68dc049375fb46bb446ec40 | Ruby | learn-academy-2021-delta/week-4-assessment-SunkissedQueen | /code_challenges.rb | UTF-8 | 1,971 | 4.71875 | 5 | [] | no_license | # ASSESSMENT 4: Ruby Coding Practical Questions
# MINASWAN
# --------------------1) Create a method that takes in a number and determines if the number is even or odd. Use the test variables provided.
num1 = 7
# Expected output: '7 is odd'
num2 = 42
# Expected output: '42 is even'
num3 = 221
# Expected output: '221 i... | true |
9c03985f3d4574839845b409b63b43faa1445489 | Ruby | gowsik-ragunath/comparator | /lib/comparator/array.rb | UTF-8 | 554 | 2.984375 | 3 | [
"MIT"
] | permissive | module Comparator
class CompareArray
class ArrayInitializeError < StandardError
def message
"Pass more than one array"
end
end
def does_it_work?
true
end
def array_comparator(*args)
if args.length > 1
difference_hash = {}
evaluation_array = args[0... | true |
9a992c07cb6ad90a7a1fb16c6d74b7a70a99df9b | Ruby | ch1c0t/typ | /src/Typ/Error/BadAssertion:self.class.rb | UTF-8 | 97 | 2.796875 | 3 | [] | no_license | def initialize it, method_name
message = "#{it.inspect} is #{method_name}"
super message
end
| true |
075b5bcb5fa3f9ab3356f9acecfa39a0358608d2 | Ruby | makoto417/oriapp | /spec/models/user_spec.rb | UTF-8 | 2,859 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe 'ユーザー情報の保存' do
before do
@user = FactoryBot.build(:user)
end
context 'ユーザー情報が保存される場合' do
it '全ての値が正しく入力されていれば保存できる' do
expect(@user).to be_valid
end
binding.pry
# it 'console_idが空でも保存できる' do
... | true |
df7b674bd29af5e2030eab40821da24eeb401c05 | Ruby | tomjnunez/sorting_cards_2 | /test/guess_test.rb | UTF-8 | 1,359 | 3 | 3 | [] | no_license | require 'Minitest/autorun'
require 'Minitest/pride'
require './lib/card.rb'
require './lib/guess.rb'
class GuessTest < Minitest::Test
def test_guess_exists
card = Card.new("10", "Hearts")
guess = Guess.new("10 of Hearts", card)
assert_instance_of Guess, guess
end
def test_guess_has_card_attributes_... | true |
0ac291c7ddd75b69c00bf9cd21125f5be2878ead | Ruby | nastee/theresashultz | /app/models/cat.rb | UTF-8 | 2,006 | 2.953125 | 3 | [] | no_license | require 'open-uri'
require 'net/http'
require 'aws/s3'
class Cat < ActiveRecord::Base
attr_accessible :file_name, :original_url, :url
def http
url
end
def self.build! options={}
# Error check
return false if Cat.exists?(original_url: options[:url])
return nil if options[:url].nil?
re... | true |
3c433e8a7db06cf56dbe4273ca2133036f21e473 | Ruby | jbeyer05/Project-Euler | /0086/problem.rb | UTF-8 | 1,335 | 3.625 | 4 | [] | no_license | =begin
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the opposite corner. By travelling on the surfaces of the room the shortest "straight line" distance from S to F is 10 and the path is shown on the diagram.
However, there are up to three "shortest" path candidates ... | true |
a208885283fa1c433d6d99047cab7fedb9ee4abe | Ruby | TomoMayumi/contest | /atcoder/indeednow-qualbCb.rb | UTF-8 | 422 | 2.65625 | 3 | [] | no_license | N=gets.to_i
adj=(0..N).map{[]}
(N-1).times{
a,b=gets.split.map(&:to_i)
adj[a]<<b
adj[b]<<a
}
q=[1]
ans=[]
gone=[nil]*(N+1)
gone[1]=true
while q[0]
d=q.shift
ans<<d
adj[d].each{|i|
next if gone[i]
gone[i]=true
c=r=0
l=q.size
while r<l
c=(r+l)/2
if q[c]<=i
... | true |
1c14685f698b3370062da3f7aaa9eb19cd735542 | Ruby | uznwokolo/blazing-waffle | /calculator.rb | UTF-8 | 685 | 4.125 | 4 | [] | no_license |
class Calculator
def add(a, b)
return a + b
end
def divide(a, b)
return a / b
end
def subtract(a, b)
return a - b
end
def multiply(a, b)
return a * b
end
def squared(a)
return a * a
end
def cubed(a)
return a ** 3
end
e... | true |
b8d5584bfd91ea0b39418b82a690d6eb12481746 | Ruby | zolrqlk/NaCl_internship | /team2/scenes/game/player.rb | UTF-8 | 1,326 | 2.640625 | 3 | [] | no_license | module Game
class Player < Sprite
@@player_img = Image.load("images/player.png")
@@player_img.set_color_key(C_WHITE)
def initialize
super
self.x = 300
self.y = 750
self.image = @@player_img
@speed = 5
end
... | true |
655ae5a4da8c99d6fdb54e397873227ae1e6ea14 | Ruby | stonerl/WadokuWeb | /db/get_stuff.rb | UTF-8 | 242 | 2.609375 | 3 | [] | no_license | require "pry"
str = open("WaDokuNormal.tab").read
regex = /<([^\s:>]+)>/
arr = []
str.lines.each do |line|
line.split("\t")[4].scan(regex).each do |match|
arr << match
end
end
puts arr.uniq.map{|m| "str('#{m.first}')"}.join(" >> ")
| true |
1f1a21ee33b9aeed5f62d5c21ae74b42045f9627 | Ruby | brianrip/exercism | /ruby/hamming/hamming.rb | UTF-8 | 274 | 3.3125 | 3 | [] | no_license | class Hamming
Hamming::VERSION = 1
def self.compute(src, dest)
raise ArgumentError if src.length != dest.length
hamming_number = 0
src.split('').each_with_index do |char, i|
hamming_number += 1 if char != dest[i]
end
hamming_number
end
end
| true |
e6e43094735b0d4ae3d13de8bc1c5ab23322b3e7 | Ruby | afarahmand/codingchallenges | /create_report_suboptimal.rb | UTF-8 | 11,602 | 3.125 | 3 | [] | no_license | # Opens a file and returns an array
# The array contains each line of the file in-order as a string
def read_file(path_infile)
infile = File.open(path_infile, 'r')
lines = infile.readlines
infile.close
lines.shift # Dump the first line which has identifiers but no data
lines
end
# Receives a string contai... | true |
1c081b531538cf4f6f2f7c3a1fc4fca2ae4187ec | Ruby | LaunchPadLab/decanter | /spec/decanter/parser/phone_parser_spec.rb | UTF-8 | 874 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe 'PhoneParser' do
let(:name) { :foo }
let(:parser) { Decanter::Parser::PhoneParser }
describe '#parse' do
it 'strips all non-numbers from value and returns a string' do
expect(parser.parse(:foo, '(12)2-21/19.90')).to match({:foo =>'122211990'})
end
context 'wit... | true |
8ef1f61aad939dab0449d52c6570e65104d737fd | Ruby | Jugglingdino/madLibPractice | /madLib_2.rb | UTF-8 | 4,011 | 3.34375 | 3 | [] | no_license |
#This is code for a DnD/Fantasy MadLib
shop_arr = [ " cave", " shop", " hovel", " boat", " alleyway", " unmarked door"]
#added space to each string in shop_arr/currency_arr to avoid grammatical problems
currency_arr = [" children", " gold pieces", " silver", " yams", " quarters", " bitcoins", " pennies"]... | true |
ec1fb3375fa623cb489084a82a295c59d83c59cc | Ruby | brownav/rideshare-rails | /app/models/driver.rb | UTF-8 | 739 | 3.125 | 3 | [] | no_license | class Driver < ApplicationRecord
has_many :trips
validates :name, presence: true, uniqueness: true
validates :vin, presence: true, uniqueness: true
def avg_rating
if self.trips.count == 0
return "No trips yet"
else
total_rating = 0
trip_count = 0
self.trips.all.each do |trip|
... | true |
cb702762f264fa9fcfc4239aa14caf5c3d581bc4 | Ruby | alisonlutz28/tts_programs | /Ruby/hash_practice.rb | UTF-8 | 289 | 3.84375 | 4 | [] | no_license | people = %W[Fred Nancy Vinh Alberto Rina]
ages = [22, 19, 24, 30, 25]
input = ""
position = 0
print "Enter a name: "
input = gets.chomp
position = people.index(input)
if position != nil then
puts "#{people[position]} is #{ages[position]} years old."
else
puts "I don't know who #{input} is."
end
| true |
d697e918c4fd26cbf1287c774066aea8d0562b3b | Ruby | AndraTechUS/sophity | /app/pdfs/survey_pdf.rb | UTF-8 | 2,914 | 2.546875 | 3 | [] | no_license | class SurveyPdf < Prawn::Document
def initialize(current_user,all_attempts,total_score)
super()
@current_user = current_user
@all_attempts = all_attempts
@total_score = total_score
if (@total_score >= 4.7)
@gradeLetter = "A+"
elsif (@total_score >= 4.4)
@gradeLetter = "A"
... | true |
a6f86c802c697bdc1de86870b9b019e633eb5ece | Ruby | Gavrilo-Princip/bodymedia | /lib/bodymedia/consumption_service.rb | UTF-8 | 1,389 | 2.671875 | 3 | [
"MIT"
] | permissive | module Bodymedia
class Client
def get_consumption_for_today(*args)
return get_consumption_for(date_now, args)
end
def get_consumption_for(day, *args)
if args.length == 0
return get_parsed_data "/consumption/#{day}"
else
return get_parsed_data "/consumption/micro/#{day}"... | true |
9c1659dd7a328d7b79d54d35de106e33ea0840e7 | Ruby | walidzbiri/gestion_biblio | /adherent.rb | UTF-8 | 1,962 | 3.15625 | 3 | [] | no_license | $LOAD_PATH << File.dirname(__FILE__)
require 'exceptions'
require 'customized_array'
status = ["Etudiant", "Enseignant"]
class Adherent
@@compteur=0
def self.compteur_id
@@compteur
end
attr_accessor :nom,:prenom,:statut,:empruntes,:id
def initialize(nom,prenom,statut)
@@compteur+=1... | true |
069a76b81a9f553b06b5d241bbf7c6cb6c7fc4c7 | Ruby | dwayne/whitespace-ruby | /test/whitespace/instructions/io/readc_test.rb | UTF-8 | 2,109 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require "test_helper"
module Whitespace::ISA
describe Readc do
before do
@vm = Whitespace::VM.new
@stdin = Object.new
end
describe "#execute" do
describe "when there is no character" do
it "raises ArgumentError" do
def @stdin.getc
end
console = Wh... | true |
28875ef14ec707104f146288913123279395c897 | Ruby | lcmccartney/flashcards | /lib/round.rb | UTF-8 | 1,104 | 3.796875 | 4 | [] | no_license | class Round
attr_reader :deck, :guesses, :number_correct, :card_number
def initialize(deck)
@deck = deck
@guesses = []
@number_correct = 0
@card_number = 1
end
def current_card
@deck.cards[@card_number - 1]
end
def record_guess(response)
guess = Guess.new(response, current_card)
... | true |
9aac9b2e820a685f341a80bc612f4f7359db83fd | Ruby | corya0687/project-euler-largest-palindrome-product-e-000 | /lib/largest_palindrome_product.rb | UTF-8 | 148 | 2.890625 | 3 | [] | no_license | # Implement your procedural solution here!
def is_palindrome?(num)
num = Array(num)
if num == num.reverse
true
else
false
end
end | true |
0a0ecdae06e0c7a3f9dc818a51fe8c5733a9d6e6 | Ruby | pond/rcvsweb | /app/controllers/application.rb | UTF-8 | 7,938 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | # RCVSweb - a Ruby On Rails wrapper around the Perl-based FreeBSD
# version of the CVSweb and Python-based CVShistory.
#
# See "http://www.freebsd.org/projects/cvsweb.html" and
# "http://www.jamwt.com/CVSHistory/"
#
# This wrapper was created for the sole purpose of embedding CVSweb
# ... | true |
d8740209ec1771e8c08899a53dd0278d665741ff | Ruby | mitchellhenke/timber-ruby | /lib/timber/events/controller_call.rb | UTF-8 | 1,891 | 2.625 | 3 | [
"ISC"
] | permissive | require "timber/event"
require "timber/util"
module Timber
module Events
# The controller call event tracks controller invocations. For example, this line in Rails:
#
# Processing by PagesController#home as HTML
#
# @note This event should be installed automatically through integrations,
# ... | true |
e21962007e7113284300227a98c021146156a4c3 | Ruby | ricardobaumann/rubytechtalk | /or_assignment.rb | UTF-8 | 163 | 2.8125 | 3 | [
"MIT"
] | permissive | variable = variable ? variable : "value"
puts variable
variable = nil
variable = variable || "value"
puts variable
variable = nil
variable ||="value"
puts variable | true |
a72d062a9f1bd484d81e01097d5d30a14097735f | Ruby | gcrk/seir41-homework | /Andre Anggono/week_04/day_04/main.rb | UTF-8 | 1,817 | 2.71875 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
require 'sqlite3'
get '/' do
@inventories = query_db("SELECT * FROM inventories")
erb :home
end
get '/inventory' do
@inventories = query_db("SELECT * FROM inventories")
erb :inventory
end
post '/inventory' do
params[:image] = "https://via.placeholder.com/300" if... | true |
01d4ec67b26f8776f5046256aac83b72588d2c6a | Ruby | veelenga/fcdk | /spec/model/match_spec.rb | UTF-8 | 2,220 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
module Fcdk
module Model
describe Match do
let(:params) { {:month => 3,
:day => 12,
:opponent => 'Shakhtar',
:home => true,
:competition => 'Ukrainian Premier League',
:round ... | true |
fed2f5492395d5ef45cffa20b927f1704b52a20d | Ruby | marocchino/refactoring-ruby-edition | /ch6/remove_assignments_to_parameters_before.rb | UTF-8 | 97 | 2.734375 | 3 | [] | no_license | def discount(input_val, quantity, year_to_date)
if input_val > 50
input_val -= 2
end
end
| true |
345b7ef4a1c3e0aa1f27c54e47099b1e76e50dfe | Ruby | nataliagalan/programming-univbasics-4-simple-looping-lab-chi01-seng-ft-080320 | /lib/simple_loops.rb | UTF-8 | 445 | 4 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Write your methods here
def loop_message_five_times(message)
message = "Hello World."
counter = 0
while counter <= 5
puts message
counter += 1
end
end
def loop_message_n_times(message, number)
counter = 0
while counter <= number
puts message
counter += 1
end
end
def output_array(array... | true |
c7699f1e2699a0a7955e0b9e0d6b8e457f547a63 | Ruby | tamaszentai/enumeration_lab | /star_system.rb | UTF-8 | 943 | 3.28125 | 3 | [] | no_license | class StarSystem
attr_reader :name, :planets
def initialize(name, planets)
@name = name
@planets = planets
end
def has_planets
@planets.count
end
def planet_names
expected_names = @planets.map {|planet| planet.name}
end
def get_planet_by_name(name)
@planets.find {|planet| planet.... | true |
a46c55cb7c03ee63b71b87f80324426869d79616 | Ruby | csb324/CaveWriter | /lib/link.rb | UTF-8 | 715 | 2.609375 | 3 | [] | no_license | require_relative 'timeline'
require_relative 'action'
class Link
attr_accessor :enabled, :remain_enabled, :color, :selected_color, :actions
def initialize(enabled: true, remain_enabled: true, color: "255, 255, 255", selected_color: "255, 255, 255")
@enabled, @remain_enabled, @color, @selected_color, @clicks_... | true |
0901e44a85be44012a3801bbca2c1ab20c12a29d | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/5018b9f9703848dd9ff75a3c74d82068.rb | UTF-8 | 240 | 3.34375 | 3 | [] | no_license | class Phrase
def initialize phrase
@phrase = phrase
end
def word_count
counts = Hash.new 0
words.each { |word| counts[word] += 1 }
counts
end
private
def words
@phrase.downcase.scan %r{[\w']+}
end
end
| true |
c675563694c90420149f55d114069b69d2f2843d | Ruby | simpleLiYu/LearnRuby | /RubyBasic/decision.rb | UTF-8 | 1,902 | 3.828125 | 4 | [] | no_license | #!/usr/bin/ruby
# -*- coding: UTF-8 -*-
require './fileRead'
fileRead = FileRead.new(__FILE__)
if ARGV.length == 0
elsif ARGV[0] == 'true'|| ARGV[0]=='TRUE'||ARGV[0]=='True'
fileRead.filtprint
elsif ARGV[0] == 'false'|| ARGV[0]=='FALSE'||ARGV[0]=='False'
fileRead.nofiltprint
else
end
#Ruby if...else语句
#if 条件 [then]... | true |
ad8636247aa4e38559cf4dc78b20fe984509818b | Ruby | joinhandshake/knockoff | /lib/knockoff/replica_connection_pool.rb | UTF-8 | 1,735 | 2.5625 | 3 | [
"MIT"
] | permissive | module Knockoff
class ReplicaConnectionPool
attr_reader :pool
def initialize(config_keys)
@pool = Concurrent::Hash.new
config_keys.each do |config_key|
@pool[config_key] = connection_class(config_key)
end
end
def clear_all_active_connections!
@pool.each do |_name, kl... | true |
42e86e337e296593de4f19446137842f031113b6 | Ruby | vladcostea/talks | /ruby_procs_blocks_and_lambdas/procs_and_lambdas_1.rb | UTF-8 | 112 | 3.28125 | 3 | [] | no_license |
# Procs and Lambdas
# procs
p1 = Proc.new { |x| puts x }
p2 = proc { |x| puts x }
p1.call(1)
p2.call(2)
| true |
888e4bd5f9cd0a5db441e552fc60781ae75f4e10 | Ruby | 645383/prproject | /app/models/country.rb | UTF-8 | 1,271 | 2.875 | 3 | [] | no_license | class Country < ActiveRecord::Base
include Countries
has_many :people, dependent: :destroy
def self.fill_from_spreadsheets(sheets)
puts "Deleting old records..."
Country.destroy_all
genders = %w(male female)
i = 2
while sheets.sheet(0).row(i)[0].present?
if sheets.sheet(0).row(i)[1].... | true |
4c7b6d69c943f6dfce49aa90a0238ddca7a8c457 | Ruby | nabiljesus/TareaRuby | /bfs.rb | UTF-8 | 9,541 | 3.546875 | 4 | [] | no_license | =begin
Módulo que define Búsqueda Generalizada en árboles binarios
y grafos. También resuelve el acertijo del Lobo, la Cabra y
el repollo.
Creado por:
Javier López
Nabil Márquez
=end
##
# Mixin para recorrido Breadth-first Search
module BFS
# Búsqueda BFS desde el nodo inicial aplic... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.