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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
7dfead1121198a00490c618f1a4dfeaf3acd02ef | Ruby | forksaber/sv | /lib/sv/job.rb | UTF-8 | 3,839 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'pathname'
module Sv
class Job
attr_reader :name
attr_writer :working_dir, :namespace
def initialize(name)
set :name, name
end
def name
attributes.fetch :name
end
def group
@namespace ? "#{name}.#{@namespace}" : name
end
def command(*args)
set_o... | true |
cebbb3fdf5f3813e056c3dfb89625a9691d6b77d | Ruby | rlmark/shipping-app-client | /app/models/order.rb | UTF-8 | 548 | 2.640625 | 3 | [] | no_license | class Order < ActiveRecord::Base
has_many :items, class_name: "LineItem"
has_one :address
has_one :credit_card
validates :number, uniqueness: true
before_create :set_number
def total
items_sum = Money.new items.sum(:total_cents)
shipping = Money.new shipping_price
items_sum + shipping
end
... | true |
fd93d9fc62a908dece4dde82d4be1c1bd4ddbec3 | Ruby | stp-che/timus | /lib/1910.rb | UTF-8 | 427 | 2.96875 | 3 | [] | no_license | n = gets.to_i
sections = gets.split(' ').map{|s| s.to_i}
max_power = 0
found_section = nil
power = sections[0,3].inject(&:+)
current_section = 1
while current_section < n-1 do
if max_power < power
max_power = power
found_section = current_section
end
current_section += 1
power += sections[current_sec... | true |
7b1dc58cc097f1f7048ad658aa9143c01de77ecf | Ruby | Jerrycharles44/ruby-music-library-cli-noukod-000 | /lib/artist.rb | UTF-8 | 790 | 2.984375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist
extend Concerns::Findable
@@all=[]
attr_accessor :name,:genres,:artist
attr_reader :songs
def initialize(name)
@name=name
@songs=[]
end
def self.all
@@all
end
def save
@@all << self
end
def self.destroy_all
@@all=[]
end
def s... | true |
77dd1d25985874dc5ced0fc3f5713443c74d4971 | Ruby | kemlyn/tic-tac-toe | /lib/game.rb | UTF-8 | 991 | 3.59375 | 4 | [] | no_license | WIN = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7]].freeze
class Game
attr_accessor :players, :board
def initialize(board = Board.new, player = Players.new)
@score = 0
@board = board
@player = player
end
def win
@player.move == WIN
end
def lose
... | true |
e95e54db98a52f8866e180e58cce64ec8b124a25 | Ruby | patrickviet/pvtools | /consul/consul.rb | UTF-8 | 1,866 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby
# -----------------------------------------------------------------------------
# Simple client for the Consul HTTP API
# Just require 'consul' (well here, require_relative 'consul')
# Then c = Consul.new, and c.setkey('test','somevalue'), puts c.getkey('test')
# -----------------------------------... | true |
be79e3c6c76b147814ba8a0fbf18ab24a73196c8 | Ruby | skellz/Charlie | /music/db/seeds.rb | UTF-8 | 1,250 | 2.515625 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
5dabf41dbd43119432c1d906889f5671bc947b8c | Ruby | magnetised/locat | /lib/locat/gitloc.rb | UTF-8 | 3,954 | 2.671875 | 3 | [
"BSD-2-Clause"
] | permissive | require 'rubygems'
require 'grit'
require 'open-uri'
require 'fileutils'
require 'date'
# Fix 1.8.7 bug
class Time
public :to_date
end
module LOCat
# Based on `git-line-count.rb` by Tieg Zaharia
class GitLOC
include Grit
MAX_COMMITS = 1_000_000
OUTPUT_FILE = "gitloc.html"
#FILE_EXTENSIO... | true |
de6087c2fd34a21c6623a05246b05c9e1e0adb08 | Ruby | jacqueline-homan/FizzBuzzAlgorithm | /lib/FizzBuzzAlgorithm.rb | UTF-8 | 625 | 3.375 | 3 | [
"MIT"
] | permissive | require "FizzBuzzAlgorithm/version"
module FizzBuzzAlgorithm
def self.convert(arg)
res = ""
#if arg % 15 == 0
# 'fizzbuzz'
#elsif arg % 5 == 0
# 'buzz'
#elsif arg % 3 == 0
# 'fizz'
#end
if arg % 3 == 0
res << "fizz"
end
if arg % 5 == 0
res << "buzz"
end
res
end
end
... | true |
6af3326434b588f6510ba5a71f86b621b6b40fd6 | Ruby | nicosaki/stacks-queues | /Stack.rb | UTF-8 | 277 | 3.296875 | 3 | [] | no_license | class Stack
attr_accessor :store
def initialize
@store = Array.new
end
def pop
@store.pop #returns removed element from mutation
end
def push(element)
@store << element
end
def size
@store.size
end
def empty?
@store.empty?
end
end
| true |
ccc0ed5b2684fac0e3017c098a6ee8e4fa20dd71 | Ruby | vargad/exercises | /elementary/best-stock.rb | UTF-8 | 319 | 3.015625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
def best_stock(data)
return data.sort_by{|k,v| v }[-1][0]
end
if __FILE__ == $0
puts(best_stock({ CAL: 42.0, GOG: 190.5, DAG: 32.2 }))
raise unless best_stock({ CAL: 42.0, GOG: 190.5, DAG: 32.2 }) == :GOG
raise unless best_stock({ CAL: 31.4, GOG: 3.42, APL: 170.34 }) == :APL
end
| true |
578b445f007047cfb586df08a60d7dc5ce9ea20a | Ruby | Gui2908/Rails_car_app-testing-unfinished | /app/models/car.rb | UTF-8 | 304 | 3.640625 | 4 | [] | no_license | class Car
attr_accessor :speed,:make,:model
def initialize(make=" ",model=" ", speed=0)
@speed = speed
@make = make
@model = model
end
def accelerate()
@speed = speed + 10
end
def brake()
if @speed-7>0
@speed = speed - 7
else
@speed=0
end
end
end
| true |
2cd764aab79f1c505a5e429d0d5414113a613cf1 | Ruby | AnastasiyaGavrilik/homeworks-2020 | /HW03/Kate Fedotova/student.rb | UTF-8 | 563 | 3.265625 | 3 | [] | no_license | class Student
attr_accessor :name, :surname, :homeworks, :mentor
def initialize(name, surname)
@name = name
@surname = surname
@homeworks = []
end
def submit_homework(homework)
@homeworks << homework
notification_message = "#{name} #{surname} submit homework:#{homework.data}"
send_noti... | true |
024da05176d238b3d08bbd7382300499e697ef18 | Ruby | AssassinPig/my_src | /ruby/common_example/code_counter.rb | UTF-8 | 271 | 2.890625 | 3 | [] | no_license | require './utils.rb'
def format_lines(lines)
lines.each_with_index do |l, i|
print "#{i+1}: #{l}"
end
print "total: #{lines.size}\n"
end
def get_code_info(file)
print "#{file}\n"
lines = get_lines(file);
format_lines(lines);
end
get_code_info(ARGV[0])
| true |
c3dc76251c6f0ce07c4e8abee62b9a40fbbe21b2 | Ruby | shivakumaarmgs/ember-boston-tryout | /rails/db/seeds.rb | UTF-8 | 1,358 | 2.59375 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
aec2376b643d863ad73c2ba3c97c203f5d4c1cdc | Ruby | samdmarshall/danger | /Dangerfile | UTF-8 | 2,554 | 2.625 | 3 | [] | no_license | # Warn when there is a big PR
warn('Big PR') if git.lines_of_code > @SDM_DANGER_BIG_PR_LINES
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
warn('PR is classed as Work in Progress') if github.pr_title.include? '[WIP]'
# determine if any of the files were modified
def didModify(file... | true |
10f6e850f46885e1f82f6595035fc11990bdfd06 | Ruby | fauzanqadri/string_match | /test/string_test.rb | UTF-8 | 1,847 | 2.953125 | 3 | [] | no_license | require 'helper'
class StringTest < Minitest::Test
def test_ngrma_when_not_giving_params
assert_equal ["H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d"], "Hello World".to_ngram
end
def test_ngram_when_string_size_more_than_one
assert_equal ["He", "el", "ll", "lo", "o ", " W", "Wo", "or", "rl", "l... | true |
cd62f03078e9a7e170a4bddff62e2130245c97eb | Ruby | natstar93/takeaway-challenge | /lib/menu.rb | UTF-8 | 104 | 2.796875 | 3 | [] | no_license | class Menu
attr_reader :dishes
def initialize
@dishes = {:Noodles=>3.0, :Rice=>2.5}
end
end | true |
b6da0c4c182d408bf0de4f50e7bf487cf62cac2f | Ruby | crtang/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 894 | 4.3125 | 4 | [] | no_license | #write your code here
def echo phrase
phrase
end
def shout phrase
phrase.upcase
end
def repeat phrase, num_of_repeats = 2
arr = []
num_of_repeats.times do
arr.push(phrase)
end
arr.join(" ")
end
def start_of_word phrase, num_of_letters
phrase[0...num_of_letters]
end
def first_word phrase
words = phrase.s... | true |
593d92c8c1aebf3deec316a4017487de4b7e2ae8 | Ruby | RinahPh/projet_validant_2 | /lib/00_hello.rb | UTF-8 | 217 | 3.21875 | 3 | [] | no_license | def say_hello(first_name)
puts "Bonjour, " + first_name
end
def ask_first_name (prenom)
puts "quel est ton prénom?"
print " ===>"
prenom = gets.chomp
return say_hello(prenom)
end
puts ask_first_name("")
| true |
ce40d97af58192ec01e694874103d70494a4d4c0 | Ruby | tfrasc/SierraDevAcademy | /Object_Design/chess.rb | UTF-8 | 2,230 | 3.796875 | 4 | [] | no_license | #colorize
#chess unicode
BLACK_SQUARE = "\u25A1".encode('utf-8')
WHITE_SQUARE = "\u25A0".encode('utf-8')
WHITE_KING = "\u2654".encode('utf-8')
BLACK_KING = "\u265A".encode('utf-8')
WHITE_QUEEN = "\u2655".encode('utf-8')
BLACK_QUEEN = "\u265B".encode('utf-8')
WHITE_ROOK = "\u2656".encode('utf-8')
BLACK_ROOK = "\u265C".e... | true |
ad9db095fbe2e9440e39057a68a8e823b5375af4 | Ruby | cvalesares/dpl_2108 | /lib/author.rb | UTF-8 | 404 | 3.046875 | 3 | [] | no_license | require './lib/book.rb'
class Author
attr_reader :name,
:books,
:book
def initialize(info)
@name = info[:first_name] + " " + info[:last_name]
@books = []
end
def write(title, date)
end
# def write(new_title, new_date)
# @new_book = Book.new(new_title, new_date... | true |
a644f0181c6fdce1d18dc696a2e683b9cafca8fb | Ruby | theironyard-rails-atl/jamesdabbs | /08-04/solutions/questions.rb | UTF-8 | 1,877 | 4.1875 | 4 | [] | no_license | ### 1. Class Questions
# Update (/ rewrite) your quiz script to
#
# 1.
# * Define a Question class
# * Use Question objects in place of the hashes used
# earlier
#
# 2.
# * Be more flexible about user input (can use a or 1)
# * Validate and handle bad user input
require "pry"
class Question
attr_reader :prom... | true |
fa9b819b7dad07e4a82fd0a6af5e42bfcaef69be | Ruby | ReinLinTaipei/alphacamp_game | /magician.rb | UTF-8 | 633 | 3.609375 | 4 | [] | no_license | require "./hero"
class Magician < Hero
attr_accessor :mp
def initialize(name, hp, ap, mp)
super(name, hp, ap)
@mp = mp
end
def attack(enemy)
if(mp > 3)
fireball(enemy)
else
super(enemy)
end
end
private
def fireball(enemy)
damage = 3*rand(5..5+@mp/3)
cost = dam... | true |
aab527e1462091ddbbbec35654efb44016a04786 | Ruby | mschulkind/whiteboard | /app/models/board.rb | UTF-8 | 271 | 2.578125 | 3 | [] | no_license | class Board
include Mongoid::Document
embeds_many :lines
def as_json(options={})
{
lines: lines.map do |line|
{
points: line.points.map do |point|
{x: point.x, y: point.y}
end
}
end
}
end
end
| true |
edd996917f06bc8b61b3a9a90a683814b00c97f6 | Ruby | Miss-Cheese/programming-univbasics-4-building-nested-hashes-nyc-web-111819 | /intro_to_ruby_hashes_lab.rb | UTF-8 | 949 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def base_hash
# Remember implicit return! We're returning this new Hash _without_ the
# keyword "return." Nice and neat.
{:railroads => {}}
end
def monopoly_with_second_tier
{:railroads => {:pieces => 4}}
end
def monopoly_with_third_tier
abc = monopoly_with_second_tier()
abc[:railroads][:rent_in_dollars] = ... | true |
6983d46d3079975ec4143e68b1ca9639f47e8960 | Ruby | honeycombio/libhoney-rb | /lib/libhoney/response.rb | UTF-8 | 769 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'http/response/status'
module Libhoney
class Response
# The response status from HTTP calls to a Honeycomb API endpoint.
#
# For most of the life of this client, this response object has been
# a pass-through to the underlying HTTP library's response object.
# This class in the Libhoney n... | true |
6ca2264ae9ed182ef02d802c284a5a39eb9e77c1 | Ruby | jmtsharpe/Unfair-BnB | /db/seeds.rb | UTF-8 | 913 | 2.515625 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
54b1b0f45695e03ab2cb18b39070f31ca63ac20f | Ruby | take4s5i/qtcmd | /spec/qtcmd_spec.rb | UTF-8 | 9,915 | 2.640625 | 3 | [] | no_license |
require 'spec_helper'
require 'qtcmd'
describe 'QtCmd' do
describe 'SwitchOption' do
let(:opt) { QtCmd::SwitchOption.new('h','help','test') }
it '名前と説明が取得できること' do
expect(opt.name).to eq 'h'
expect(opt.long_name).to eq 'help'
expect(opt.desc).to eq ... | true |
1e0427cd81bb1dde7acd5fa314e12ea6bc5c6c7e | Ruby | IsaiahJean/LS_Courses_1 | /LS_101/lesson_5/tictactoe.rb | UTF-8 | 4,781 | 3.75 | 4 | [] | no_license | require 'pry'
WINNING_LINES = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + # rows
[[1, 4, 7], [2, 5, 8], [3, 6, 9]] + # col
[[1, 5, 9], [3, 5, 7]] # diagonals
INITIAL_MARKER = ' '
PLAYER_MARKER = 'x'
COMPUTER_MARKER = 'O'
FIRST_MOVE = 'choose'
def prompt(msg)
puts "=> #{msg}"
end... | true |
845bddf81aa7a479463fb09200c7d6e14273924a | Ruby | flowlink/quickbooks_integration | /lib/qb_integration/services/journal_line.rb | UTF-8 | 3,494 | 2.6875 | 3 | [
"BSD-3-Clause"
] | permissive | module QBIntegration
module Service
class JournalLine < Base
attr_reader :line_items, :lines, :config, :journal_entry
attr_reader :account_service, :customer_service, :class_service
LINE_MISSING_ZERO_ERROR ||= "Both the credit and debit amounts are non-zero. Journal lines must contain at least ... | true |
00a03c4eee914df239303e07f881c6e3c5246dd0 | Ruby | ShaunDaneJames/backend_module_0_capstone | /day_3/exercises/ex31.rb | UTF-8 | 1,490 | 3.953125 | 4 | [] | no_license | puts "You enter a dark room with two doors. Do you go through door \#1, door \#2, or take the mystery prize behind door \#3?"
print "> "
door = $stdin.gets.chomp
if door == '1'
puts "There;s a giant bear hear eating cheese cake. What do you do?"
puts "1. Take the cake."
puts "2. Scream at the bear."
print ">... | true |
a7b84fd775868bb06f09f231876a53acfcb2acac | Ruby | crawsible/advent-2019 | /07/lib/amplification_series.rb | UTF-8 | 652 | 3.109375 | 3 | [] | no_license | class AmplificationSeries
def initialize(amplifiers)
@amplifiers = amplifiers
chain_amplifiers
end
def amplify(phases)
amplifiers.each.with_index do |amplifier, i|
amplifier.input.enq(phases[i])
end
amplifiers[0].input.enq(0)
threads = amplifiers.map do |amplifier|
Thread.ne... | true |
14d9782f16418e6ba586d00a4943a0a3c2f1adc7 | Ruby | dylanmckay/rails-euchre | /spec/concepts/game_state_spec.rb | UTF-8 | 3,819 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
require_relative '../game_helper'
describe GameState do
let(:player_models){
create_player_models(3)
}
let(:players) {[
PlayerState.new(hand: create_hand, player: player_models[0]),
PlayerState.new(player: player_models[1]),
PlayerState.new(player: player_models[2]),
... | true |
53724348405710beb8b70534ab850fdbd23f81df | Ruby | A-Hayashi/system_trade | /lib/rule/exit/estrangement_exit.rb | UTF-8 | 546 | 2.75 | 3 | [] | no_license | # coding: utf-8
require "./lib/base"
class EstrangementExit < Exit
def initialize(params)
@span = params[:span]
@rate = params[:rate]
end
def calculate_indicators
@estrangement = Estrangement.new(@stock, span: @span).calculate
end
def check_long(trade, index)
if @estrangement[index-1] > (... | true |
ee515b9d315d5c2e79b84c69a8c30dea976f7c58 | Ruby | adrianmarino/karajoker | /app/domain/youtube/karaoke_result.rb | UTF-8 | 285 | 2.515625 | 3 | [
"MIT"
] | permissive | module Youtube
class KaraokeResult
attr_reader :video
def to_s
"{'id': #{id}, title': '#{title}'}"
end
def title
@video['snippet']['title']
end
def id
@video['id']
end
def initialize(video)
@video = video
end
end
end
| true |
d2fcb029b82eceaf41e1489abb693a428e893712 | Ruby | cthulh/Ruby-beginnings | /Chris Pine - Learn To Program/Modern_Roman_numerals.rb | UTF-8 | 2,616 | 4.15625 | 4 | [] | no_license | # I=1/V=5/X=10/L=50/C=100/D=500/M=1000
#1-10s: 1,2,3=add/4=subtr from 5/ 5=own/6,7,8=add/9= subtr from 10
#11-100s:10,20,30=add/40=subt from 50=own/60,70,80=add/90=butr from 100
#100-1000:100,200,300=add/400=subtr from 500own/600,700,800=add/900=subt from 1000
#
def converter(x)
i=x
roman_num=[]
while i!=0... | true |
a9d6d65b1614b15161f258ec605a2df7b195cdee | Ruby | PD2015/launch_school | /programming_foundations/lesson_2/pseudo_code.rb | UTF-8 | 1,960 | 5.125 | 5 | [] | no_license |
# 1) a method that returns the sum of two integers
# 2) a method that takes an array of strings, and returns a string that is all those strings concatenated together
# 3) a method that takes an array of integers, and returns a new array with every other element
# 1) ==========================
# given two integers
# ... | true |
d6fc424080ed17398ecdcea63e20449fb8cd2264 | Ruby | Jendnice/badges-and-schedules-online-web-ft-090919 | /conference_badges.rb | UTF-8 | 464 | 3.828125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
"Hello, my name is #{name}."
end
def batch_badge_creator(array)
array.map do |name|
badge_maker(name)
end
end
def assign_rooms(speakers)
speakers.map.with_index do |speaker, index|
"Hello, #{speaker}! You'll be assigned to room #{index + 1}!"
end
end
def printer(attendees)... | true |
b2cae005e738099e673312cdb52216eb49db0073 | Ruby | jjousun/BankAccounts | /specs/checking_account_spec.rb | UTF-8 | 4,126 | 3.09375 | 3 | [] | no_license | require_relative 'spec_helper'
# TODO: uncomment the next line once you start wave 3 and add lib/checking_account.rb
require_relative '../lib/checking_account'
# Because a CheckingAccount is a kind
# of Account, and we've already tested a bunch of functionality
# on Account, we effectively get all that testing for fr... | true |
fe0a82d1cbf3a211c438bebe8d675f6bfaaa034e | Ruby | patschramm/aA-classwork | /Week-4/W4D5/two_sum.rb | UTF-8 | 1,008 | 3.921875 | 4 | [] | no_license |
def bad_two_sum?(arr, target) #O(n^2)
(0...arr.length - 1).each do |i|
(i + 1...arr.length).each do |j|
return true if arr[i] + arr[j] == target
end
end
false
end
# arr = [0, 1, 5, 7]
# p bad_two_sum?(arr, 6) # => should be true
# p bad_two_sum?(arr, 10) # => should be false
... | true |
d46375599a7643c03546238cd0d0cb0639c61c2a | Ruby | thunderboltlabs/engine-of-war | /lib/engine_of_war/layout.rb | UTF-8 | 546 | 2.609375 | 3 | [] | no_license | class Layout
attr_reader :page
def initialize(page)
@page = page
end
def name
potential_layouts.first + ".html"
end
def potential_layouts
[layout_from_directory, layout_from_meta, default_layout].reject(&:blank?).compact.select do |f|
File.exists?(File.join(page.views_root, "layouts", "... | true |
198b66bbd4d7b858984e9b6c0a6556ade2f70364 | Ruby | patrickdavey/AoC | /2015/day10/run.rb | UTF-8 | 108 | 2.84375 | 3 | [] | no_license | require './look_and_say.rb'
initial_value = 1321131112
puts LookAndSay.new(initial_value).after(50).length
| true |
8a33dc2f1bca762a959e8350f9a5b4dea02aa07c | Ruby | cristiancfe/Curso_Ruby | /Arquivos/B-hello_world.rb | UTF-8 | 254 | 3.140625 | 3 | [
"MIT"
] | permissive | # O famoso
puts "Hello world"
# Print
print "Hello "
print "World \n"
print "Hello World "
print("Hello World \n")
# Puts
puts "Hello "
puts "World"
puts "Hello World"
puts("Hello World")
# P
p "Hello "
p "World"
p "Hello World"
p("Hello World") | true |
7d2a611355c4e7b02ea01a6eddf0e3fc8e3325ee | Ruby | sideshowcoder/readinglist2readability | /lib/readability_importer.rb | UTF-8 | 772 | 2.5625 | 3 | [
"MIT"
] | permissive | require "readit"
Readit::Config.consumer_key = ENV["CONSUMER_KEY"]
Readit::Config.consumer_secret = ENV["CONSUMER_SECRET"]
Readit::Config.parser_token = ENV["PARSER_TOKEN"]
class ReadabilityImporter
def initialize tokens, bookmark_list
@bookmark_list = bookmark_list
@tokens = tokens
end
def import
... | true |
80359571d82df9827d0590f6984dd9bef2d60764 | Ruby | mattkiernan/refactoring-practice | /hotels/null_object.rb | UTF-8 | 237 | 2.953125 | 3 | [] | no_license | class NullObject
def initialize
@name = "Does not exist"
@location= "Does not exist"
@phone = "Does not exist"
@total_number_of_rooms = "Does not exist"
end
attr_reader :name, :location, :phone, :total_number_of_rooms
end
| true |
7ecef64662da036b0e35d299b42624d1da9a2f7f | Ruby | ealwafai/last_airbender | /app/facades/member_facade.rb | UTF-8 | 231 | 2.515625 | 3 | [] | no_license | class MemberFacade
def self.member_search(nation)
search_results = MemberService.search_by_affiliation(nation)
top_twenty_five_results = search_results[:members].map do |result|
Member.new(result)
end
end
end
| true |
7d27c1448fd19fc1a65a82c8989f9a5616c7fe99 | Ruby | Jennings824/launch_week_two | /kickball-site/models/player.rb | UTF-8 | 447 | 2.875 | 3 | [] | no_license | require_relative "./team_data"
class Player
attr_reader :name, :position, :team_name, :all_players
def initialize(name, position, team_name)
@name = name
@position = position
@team_name = team_name
end
def self.all
@all_players = []
TeamData::ROLL_CALL.each do|team, roster|
roster.each... | true |
164097c7e0914ccf89b183c6b66ba6833f971698 | Ruby | 8ceg6/instance-methods-lab-ruby-online-web-pt-090819 | /lib/person.rb | UTF-8 | 98 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Person
def talk
puts "Hello World!"
end
def walk
puts "The Person is walking"
end
end | true |
2f6184ad18bda1a05ca3e2b35517e3965535f934 | Ruby | timsjoberg/circus | /lib/irc/messages/join.rb | UTF-8 | 291 | 2.578125 | 3 | [
"Beerware",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Circus
module Messages
class Join
def initialize(channel)
@channel = channel
end
def to_s
if @channel =~ /^\#/
"JOIN #{@channel}"
else
"JOIN ##{@channel}"
end
end
end
end
end
| true |
5b388315390ca795129cf06305f6cda494dd2b7b | Ruby | shokai/autodiary | /libs/data.rb | UTF-8 | 573 | 2.921875 | 3 | [
"MIT"
] | permissive |
class Data
def self.[](key)
self.data[key]
end
def self.[]=(key, value)
data = self.data
data[key] = value
File.open(file, 'w+') do |f|
f.write data.to_json
end
end
def self.file
File.expand_path '../data.json', File.dirname(__FILE__)
end
def self.data
data = {}
r... | true |
55dd38552a0a3824e944eb8f069db14d4214bbb7 | Ruby | KrisD2/RB120 | /lesson_4/medium_1/q1.rb | UTF-8 | 326 | 3.4375 | 3 | [] | no_license | class BankAccount
attr_reader :balance
def initialize(starting_balance)
@balance = starting_balance
end
def positive_balance?
balance >= 0
end
end
# Ben is correct - he is using the getter method for balance.
# balance on line 9 does not refer to the instance variable,
# it refers to the method bal... | true |
a209bc6f000a421752f4773bee724951eaea435e | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grains/21b437b52af3418291890e1676eb5027.rb | UTF-8 | 221 | 3.109375 | 3 | [] | no_license | $cache = [1]
class Grains
def square num
index = num-1
if $cache.count >= num
$cache[index]
else
$cache[index] = square(num-1)*2
end
end
def total
$cache.reduce(&:+)
end
end
| true |
8d002442029ea7bd599f4d0dc3e2bbe52a973e34 | Ruby | pdxwolfy/Challenges | /PhoneNumber/phone_number.rb | UTF-8 | 785 | 3.671875 | 4 | [] | no_license | # Pete Hanson
# Phone Number Challenge
class PhoneNumber
BAD_NUMBER = '0000000000'
attr_reader :number, :area_code
def initialize(the_number)
@number = strip(the_number) || BAD_NUMBER
@area_code, @prefix, @suffix = parse @number
end
def to_s
"(#{area_code}) #{@prefix}-#{@suffix}"
end
priv... | true |
4c7895131b3e3483e3afb5a1a3e3d1a46b353c38 | Ruby | rkachowski/advent-of-code | /2018/01/solution.rb | UTF-8 | 306 | 3.0625 | 3 | [] | no_license | require 'set'
input = File.open("input").read.lines.map(&:to_i)
puts "part1 #{input.reduce(:+)}"
0.step.inject([Set.new([0]), 0]) do |(set, val), i|
index = i % input.size
val = val + input[index]
if set.member? val
puts "part2 #{val}"
exit
else
set << val
[set, val]
end
end
| true |
4780d746ed5aac2089d64c05cea1efde8c9ee345 | Ruby | mayerj/marketbot | /src/lib/parser.rb | UTF-8 | 3,944 | 2.6875 | 3 | [] | no_license | require 'net/http'
require 'nokogiri'
require './lib/evecentral'
require './lib/command'
require './lib/evefit'
class Parser
def initialize(eve_db, systems, client, data, user_id, cache)
@eve_db = eve_db
@systems_db = systems
@client = client
@data = data
@user_id = user_id
@quick_look_cache = cache
end
... | true |
8d8ec6d919a630ab455ac2aae7c458e8e1e9fbbb | Ruby | mainangethe/learn-to-code-w-ruby-bp | /section_9/unpack_a_multidimensional_array.rb | UTF-8 | 417 | 3.234375 | 3 | [] | no_license | users = %w[Gaciku Rita Judy Njoki]
users_multi_arary = [["Gaciku", 36, "Female"],
["Rita" ,32, "Female"],
["Judy", 30, "Female"],
["Njoki", 28, "Female"]]
p users_multi_arary[-1]
# to go deeper
p users_multi_arary[-1][-2] #Njoki's Age
gaciku, rita, judy = u... | true |
de09ba4cea8cc7efc4ae167b2975dc0e39eba3dd | Ruby | will-hsiao/programmingbook | /exception_example.rb | UTF-8 | 794 | 4.3125 | 4 | [] | no_license | # exception_example.rb
begin
# perform some dangerous operation
Don't konw'
rescue
# do this if operation fails
# log the error
puts 'you are fool'
end
names = ['bob', 'joe', 'steve', nil, 'frank']
names.each do |name|
begin
puts "#{name}'s name has #{name.length} letters in it."
re... | true |
be6df5b601ef4f84af5b601ce20f3d896f67d6b0 | Ruby | stupendousC/oo-ride-share | /lib/passenger.rb | UTF-8 | 2,021 | 3.53125 | 4 | [] | no_license | require_relative 'csv_record'
module RideShare
class Passenger < CsvRecord
attr_reader :name, :phone_number, :trips
def initialize(id:, name:, phone_number:, trips: nil)
# using superclass CsvRecord's initialize() to validate id
super(id)
@name = name
@phone_number = phone... | true |
90db90d2faf1bfa1d2d65600f1f8beb1b6363eb9 | Ruby | lahbibSBK/cookbook-sinatra | /cookbook.rb | UTF-8 | 1,061 | 3.484375 | 3 | [] | no_license | require 'csv'
require_relative 'recipe'
class Cookbook
attr_reader :recipes, :file_path
def initialize(file_path)
@recipes = []
@file_path = file_path
CSV.foreach(@file_path) do |row|
recipe1 = Recipe.new(row[0], row[1], row[2], row[3], row[4])
@recipes << recipe1
end
end
def all... | true |
e31ffbdc20f4fb07de47f7fd6eacbd2be28bb9dc | Ruby | yantsong/axiom | /spec/integration/axiom/relation/efficient_enumerable_spec.rb | UTF-8 | 2,544 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: utf-8
require 'spec_helper'
require 'timeout'
# use an infinite list to simulate handling a large Array.
# if any operation is inefficient, then the specs will never exit
class InfiniteList
include Enumerable
def each
0.upto(Float::INFINITY) { |index| yield [index] }
self
end
end
describe ... | true |
c694094f2111f29cad5cad8b21dbd46f32e595cc | Ruby | dlaststark/machine-learning-projects | /Programming Language Detection/Experiment-2/Dataset/Train/Ruby/problem-of-apollonius.rb | UTF-8 | 1,225 | 3.734375 | 4 | [] | no_license | class Circle
def initialize(x, y, r)
@x, @y, @r = [x, y, r].map(&:to_f)
end
attr_reader :x, :y, :r
def self.apollonius(c1, c2, c3, s1=1, s2=1, s3=1)
x1, y1, r1 = c1.x, c1.y, c1.r
x2, y2, r2 = c2.x, c2.y, c2.r
x3, y3, r3 = c3.x, c3.y, c3.r
v11 = 2*x2 - 2*x1
v12 = 2*y2 - 2*y1
v13 = x... | true |
8ee27c41528c1e64216cda8f5d64a3f726bdf56c | Ruby | ged/rake-deveiate | /lib/rake/deveiate/gem_dep_finder.rb | UTF-8 | 2,087 | 2.546875 | 3 | [] | no_license | # -*- ruby -*-
# frozen_string_literal: true
require 'set'
require 'rubygems'
require 'rake/deveiate' unless defined?( Rake::DevEiate )
# A dependency finder that groks the GemDependencyApi
class Rake::DevEiate::GemDepFinder
### Create a new GemDepFinder that will find dependencies in the given
### +depfile+.
de... | true |
445fddc97c2502bc068a2ed79e5ddc68a07d16d3 | Ruby | prevostjules/first_ruby_project | /others_object_methods.rb | UTF-8 | 472 | 3.96875 | 4 | [] | no_license | age = 27
p age.between?(28, 99) #return false
p age.between?(18, 99) #return true
p 10.5.floor #return 10
p 10.5.ceil #return 11
p 10.3.round #return 10
p 10.6.round #return 11
p 3.13434342434341343431.round(4) #return 3.1343 (4 digits after comma)
p -35.67.abs #distance from 0 => return 35.67
5.downto(1) { |i|... | true |
e45eefab2dcf5c3ea39aa6c51704d4192cb81ab4 | Ruby | allbecauseyoutoldmeso/scrbabble | /app/models/game.rb | UTF-8 | 2,657 | 2.8125 | 3 | [] | no_license | class Game < ActiveRecord::Base
has_one :tile_bag
has_one :board
has_many :players
has_many :tile_racks, through: :players
belongs_to :current_player, class_name: 'Player', optional: true
has_many :turns
after_create :create_board
after_create :create_tile_bag
after_create :assign_initial_tiles
aft... | true |
96eac5bd18022a114e056f7f932dba3f2d157285 | Ruby | Geovo/codeeval | /easy/lowest_uniq/lowest_uniq.rb | UTF-8 | 220 | 3.140625 | 3 | [] | no_license | File.open(ARGV[0]).each_line do |line|
ar = []
myarr = line.split(' ')
myarr.map {|x| ar << x if line.count(x) == 1 }
ar.sort!
if ar.length == 0
puts 0
else
puts myarr.find_index(ar[0]) + 1
end
end | true |
4719d4e62fb4c924f5575cdb1e1181950cf80dc7 | Ruby | flon-io/flon | /tst/usr/local/tsk/any/hello/r.rb | UTF-8 | 178 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive |
# saying hello
#
# Thu Mar 5 13:18:57 JST 2015
require 'json'
task = JSON.parse(STDIN.read)
task['hello'] = task['name']
task.delete('name')
STDOUT.puts(JSON.dump(task))
| true |
74c4953ec27a3ba6effd151f2ce98c3b40776f90 | Ruby | sebastianhahne/airbnb-clone | /app/controllers/instruments_controller.rb | UTF-8 | 2,037 | 2.640625 | 3 | [] | no_license | class InstrumentsController < ApplicationController
# Creating an instance of all instruments
def index
if params[:query].present?
# sql_query = "name ILIKE :query OR category ILIKE :query"
# @instruments = Instrument.where(sql_query, query: "%#{params[:query]}%")
@instruments = Instrument.se... | true |
2dcc5e3b5d7cfddbf787ae1866e9fb0a4df623ed | Ruby | code-and-effect/effective_form_inputs | /app/models/effective/form_builder_inputs/effective_radio_buttons.rb | UTF-8 | 3,571 | 2.59375 | 3 | [
"MIT"
] | permissive | module Effective
module FormBuilderInputs
class EffectiveRadioButtons < Effective::FormBuilderInput
delegate :collection_radio_buttons, :content_tag, :label_tag, :radio_button_tag, :image_tag, :to => :@template
BOOLEAN_COLLECTION = [['Yes', true], ['No', false]]
def default_options
{ l... | true |
653038cf181f4fe59bc997861f992d666e9095cd | Ruby | jichen3000/colin-ruby | /test/treetop_test/node_extensions.rb | UTF-8 | 1,093 | 2.984375 | 3 | [] | no_license | module Sexp
# Expression eg: (1 2 3)
# Identifier eg: foo, bar, other_thing
# IntegerLiteral eg: 1, 2, 99
# StringLiteral eg: “test”
# class CommaMark < Treetop::Runtime::SyntaxNode
# def to_array
# return self.text_value
# end
# end
# class PeriodMark < Treetop::Runtime::SyntaxNode
# def to_array
... | true |
a306948c1e72aba6d09182d095f93abcbaf081b7 | Ruby | kevin-lesenechal/freebj_study | /bin/strategy_to_csv.rb | UTF-8 | 730 | 2.65625 | 3 | [] | no_license | #!/usr/bin/ruby
require 'json'
require 'csv'
require_relative 'freebj'
json = JSON.parse($stdin.read)
CSV($stdout) do |csv|
csv << [rules_to_str(json["rules"])]
[json["hard_hands"], json["soft_hands"], json["pairs"]].each do |data|
data.each do |row, data|
data.each do |dealer, tcs|
row_n = ... | true |
8e37293569be1ef1e4c2f22df27a4b4adbf76c9b | Ruby | takatoshiH/AtCoder | /ABC/ABC143A.rb | UTF-8 | 88 | 3.203125 | 3 | [] | no_license | a, b = gets.chomp.split(" ").map(&:to_i)
if a > b * 2
puts a - b *2
else
puts 0
end | true |
c402fcf39950e7835beb1f55acd43ddf817d3211 | Ruby | morizotter/SwiftyDrop | /vendor/bundle/gems/fuzzy_match-2.0.4/spec/record_spec.rb | UTF-8 | 667 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe FuzzyMatch::Record do
it %{does not treat "'s" as a word} do
assert_split ["foo's", "bar"], "Foo's Bar"
end
it %{treats "bolivia," as just "bolivia"} do
assert_split ["bolivia", "plurinational", "state"], "Bolivia, Plurinational State"
end
it %{does not split up h... | true |
e24a180f231892a1c2fbebd47c0ee440e528fc43 | Ruby | michellebonat/bitparrot | /spec/features/visitors/home_page_spec.rb | UTF-8 | 367 | 2.53125 | 3 | [
"MIT"
] | permissive | # Feature: Home page
# As a visitor
# I want to visit a home page
# So I can learn more about the website
feature 'Home page' do
# Scenario: Visit the home page
# Given I am a visitor
# When I visit the home page
# Then I see "Welcome"
scenario 'visit the home page' do
visit root_path
exp... | true |
0d358df4b1a10b3963f0447d46a52e5dd037a20f | Ruby | Shuotong/sp15-hw2 | /app/controllers/concerns/person.rb | UTF-8 | 263 | 3.53125 | 4 | [] | no_license | class Person
def initialize(name,age)
@name = name
@age = age
@nickname = name[0..4]
end
def introduce
@nickname + @age
end
def birth_year
2015 - @age.to_i
end
def nickname
@nickname
end
def name
@name
end
def age
@age
end
end | true |
82420d8d9bc71feebdd9454bb20fcda5272b4825 | Ruby | ideamans/image-format-compare | /main.rb | UTF-8 | 4,824 | 2.640625 | 3 | [] | no_license | require 'ostruct'
require 'open3'
def sources
# ノイズの粒度によるバリエーション
sources = Dir.glob('./original/*').map do |f|
ext = File.extname f
filename = File.basename f, ext
tiff = File.join('./tiff', "#{filename}.tif")
`convert -compress none -alpha remove #{f} #{tiff}`
values = {}
values[:type] =... | true |
e8bd26f5c0fe130bdab72448e48f4ddd88bc8d2e | Ruby | faradayio/carbon-old | /lib/carbon/shell/emitter.rb | UTF-8 | 4,218 | 2.703125 | 3 | [
"MIT"
] | permissive | module Carbon
class Shell
class Emitter < Bombshell::Environment
include Bombshell::Shell
include Carbon
def initialize(name, input = {})
@emitter = name
@input = input
characteristics_url = "http://carbon.brighterplanet.com/#{@emitter.to_s.pluralize}/options.json"... | true |
5cf6bd3e9b87575973df88726a8947484236f832 | Ruby | iliabylich/exception_manager | /spec/exception_manager/patch_spec.rb | UTF-8 | 2,702 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe ExceptionManager do
subject(:error) do
begin
Letter.new('message', 'from@example.com').deliver_to('to@example.com')
rescue => e
e
end
end
describe 'Kernel.raise' do
it 'still raises exception' do
expect { raise 'foo' }.to raise_error(RuntimeError)... | true |
ba909b4801d552a92a3273721e10894a8067c359 | Ruby | daveb1392/count-elements-london-web-062419 | /count_elements.rb | UTF-8 | 423 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def count_elements(array)
# code goes here
# counter = 0
# new_hash = {}
# instead of setting a new hash I used the Hash.new method and inject enumerator.
new_hash = array.inject(Hash.new(0)) {|hash, arr_element| hash[arr_element] +=1; hash}
# this should work in ruby 2.7
# new_hash = array.tally
#th... | true |
117eac8e304a49bf415bfeb09e51284edf5ef1ed | Ruby | giroma/crowdfunder | /app/models/pledge.rb | UTF-8 | 524 | 2.578125 | 3 | [] | no_license | class Pledge < ApplicationRecord
belongs_to :user
belongs_to :project
validates :dollar_amount, presence: true
validates :user, presence: true
# validate :owner_cannot_back_own_project
validate :must_be_positive
def owner_cannot_back_own_project
if project.user == user
errors.add(:user_id, ... | true |
e3b6fd236c37dab29798e03f5673fd50ce831cca | Ruby | SREENANDINIMALLELA/cw_w2_classes_multipleclasses | /day_1/classes/bank_account.rb | UTF-8 | 1,018 | 3.46875 | 3 | [] | no_license |
class BankAccount
# attr_reader :type ,:balance,:holder_name
# attr_writer :type , :balance,:holder_name
attr_accessor :holder_name ,:type ,:balance
#attr_accessor will make getters and setters
def initialize(holder_name , balance , type)
@holder_name =holder_name
@balance = balance
@type = type
e... | true |
e6f7b340caf490ffc40651717f29c66419548433 | Ruby | simcase/xero_gateway | /lib/xero_gateway/item.rb | UTF-8 | 1,016 | 2.734375 | 3 | [
"ISC"
] | permissive | module XeroGateway
class Item
attr_accessor :code, :name, :description, :sales_details
def initialize(params = {})
params.each do |k,v|
self.send("#{k}=", v)
end
end
def to_xml(b = Builder::XmlMarkup.new)
b.Item {
b.Code code
b.Name name
b.Descripti... | true |
76ad8fe1b5c0e96a4a6278982050ce49a50f185b | Ruby | naasfu/ctrlalt.io | /app/services/add_bro_variant_to_cart.rb | UTF-8 | 975 | 2.625 | 3 | [] | no_license | class AddBroVariantToCart
def self.call(variant_id, cart)
variant = BroVariant.includes(:bro_sale).find(variant_id)
if variant.present?
add_to_cart(variant, cart)
else
raise 'Please select an option to add this bro to your cart.'
end
end
private
def self.add_to_cart(variant, cart)
... | true |
074494b92d8ea7c67daeaa5beca752a5159ac886 | Ruby | vkwong/exercisms | /ruby/crypto-square/crypto_square.rb | UTF-8 | 566 | 3.234375 | 3 | [] | no_license | class Crypto
attr_reader :plaintext
def initialize(plaintext)
@plaintext = plaintext
end
def normalize_plaintext
@normalized ||= plaintext.downcase.gsub(/\W/, '')
end
def size
Math.sqrt(normalize_plaintext.length).ceil
end
def plaintext_segments
chunk(normalize_plaintext, size)
end
def ciphertex... | true |
376fdc8d953002ae9d192f2b44d40e5aebfa2297 | Ruby | Cazovo/square_array-onl01-seng-ft-090820 | /square_array.rb | UTF-8 | 139 | 3.625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
squared_numbers=[]
array.each do |x|
squared_numbers.push(x**2)
end
return squared_numbers
end | true |
53b05b0687421d57c5d66047465a0ed0a54ca41d | Ruby | RobotClubKut/festival_timer_2014 | /inifiles.rb | UTF-8 | 3,470 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'Win32API'
$lstrlen = Win32API.new('kernel32', 'lstrlenA', %w(P), 'L');
$GetPrivateProfileString = Win32API.new('kernel32', 'GetPrivateProfileString', %w(P P P P L P), 'L');
$GetPrivateProfileString3I = Win32API.new('kernel32', 'GetPrivateProfileString', %w(I I I P L P), 'L');
$GetPrivateProfileString... | true |
89b5b0a935b3645ba6af3f9e7c550deb77449624 | Ruby | iExperience/session0202_exercises | /JulianChernyk-julianche/d4/phonebook_app/app.rb | UTF-8 | 313 | 2.75 | 3 | [] | no_license | require "sinatra"
get "/" do
erb :index
end
get "/contacts" do
@contacts = [:josh, :sammy, :praise]
erb :contacts
end
get "/contacts/:contact" do |contact|
contacts = {"josh" => "07123456", "sammy" => "07214556", "praise" => "07123432"}
@contact = contact
@phone = contacts[contact]
erb :contact
end | true |
183e8d6db6546ed36c50ee4604dd9dcba7a19e34 | Ruby | hefese/lugat | /lugat | UTF-8 | 1,813 | 3.015625 | 3 | [] | no_license | #!/usr/bin/env ruby
require './DictionaryProcesses'
# Initialize variables
min = 0
max = 0
charset = nil
fileName = nil
pattern = nil
lang = nil
# Fetching Arguments From Console
ARGV.length.times do |i|
if ARGV[i] == "-m" or ARGV[i] == "--min"
min = ARGV[i+1]
elsif ARGV[i] == "-M" or ARGV[i] == "--max"
max =... | true |
c73fdcfd98d9e1bc3a6b265c907ccaf74f713bff | Ruby | Cliffsky/jungle-rails | /spec/models/user_spec.rb | UTF-8 | 4,054 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe 'Validations' do
it 'should insert a user when credentials are provided properly' do
user = User.new(name: Faker::Internet.user_name, email: Faker::Internet.email, password:'abcdefgh', password_confirmation:'abcdefgh')
expect(user).... | true |
e4c790628aa521d63d4f1ca4531168d3f54b958b | Ruby | bmanandhar/ruby-practice | /js_hw_w2d1.rb | UTF-8 | 858 | 4.6875 | 5 | [] | no_license | =begin
# Two-Sum
# Define a method, #two_sum, that accepts an array
and a target sum (integer) as arguments.
# The method should return true if any two integers
in the array sum to the target.
# Otherwise, it should return false.
Assume the array will only contain integers.
=end
def two_sum(array, target)
... | true |
b19718da6f2e9bcd524da3d3a298c5d7f588ae9f | Ruby | Bykanir/ruby_lessons | /Lesson_18/gamer.rb | UTF-8 | 167 | 3.3125 | 3 | [] | no_license | require_relative 'player.rb'
class Gamer < Player
attr_reader :name
def get_name
puts "What is you name?"
name = gets.chomp
@name = name
end
end
| true |
601cb3355c8e3a12776345e32a38fa5e3756aa07 | Ruby | sharath666/wd-june | /ruby/gift.rb | UTF-8 | 1,357 | 3.484375 | 3 | [] | no_license | =begin
wishlist = [
{name: "Mini Puzzle", size: "small", clatters: "yes", weight: "light"},
{name: "Toy Car", size: "medium", clatters: "a bit", weight: "medium"},
{name: "Card Game", size: "small", clatters: "no", weight: "light"}
];
presents = [
{size: "medium", clatters: "a bit", weight: "mediu... | true |
f58655ab76dc8c2b66dd125e64ebe78747c06bdb | Ruby | RubyDaRosess/ruby-exo | /exo_03.rb | UTF-8 | 289 | 3.109375 | 3 | [] | no_license | puts "Bonjour, monde !"
#puts "Et avec un voix sexy, ça donne : Bonjour, monde !"
=begin
La ligne 2 ne s'affiche plus dans la console car elle est considérée comme
un commentaire, elle n'est pas lue par le compilateur, cela sert à commenter son code
pour que ce soit plus clair
=end | true |
5fd2217f6b6314e364d825643969c8bbacff350a | Ruby | ragga47/Samplecode | /def7.rb | UTF-8 | 36 | 2.90625 | 3 | [] | no_license | def area(x)
x * x
end
puts area(3) | true |
10c450686f0ed445111f6989b84d2780b12a2a20 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/d2c502fe2acd46649ad80d41b14461ef.rb | UTF-8 | 421 | 3.484375 | 3 | [] | no_license | require 'prime'
class Raindrops
SOUNDS = {
3 => 'Pling',
5 => 'Plang',
7 => 'Plong',
}
def self.convert(number)
new(number).convert
end
attr_reader :n
def initialize(number)
@n = number
end
def prime_factors
Prime.prime_division(n).map(&:first)
end
def convert
sound... | true |
058eda8d62af8afe5be2f4fb5c1c48d2293bc23a | Ruby | NikantVohra/CS-169.1_edx_SAAS_course | /HW1/public/lib/fun_with_strings.rb | UTF-8 | 810 | 3.28125 | 3 | [] | no_license | module FunWithStrings
def palindrome?
word = self.downcase.gsub(/[^a-z]/,"")
word == word.reverse
end
def count_words
frequency = {}
self.split.each do |word|
word = word.downcase.gsub(/[^a-z]/,"")
if /[a-z]/ =~ word
if frequency.keys.include? word
frequency[word] += 1
else
frequency[w... | true |
7d922314abf6f232522898adb6d1e5fec9e99015 | Ruby | OdeliaFink/Two-O-Player | /player.rb | UTF-8 | 136 | 3.203125 | 3 | [] | no_license | class Player
attr_accessor :name, :lives
def intialize(name)
@name = name
@lives = 3
end
def update_life
@lives -= 3
end
end | true |
a8d7e257cd39c87b26bb10a6e254589ef4519984 | Ruby | leftees/mission_control | /spec/mission_control/rover_spec.rb | UTF-8 | 3,031 | 2.75 | 3 | [
"MIT"
] | permissive | module MissionControl
describe Rover do
describe '#move' do
let(:x) { 1 }
let(:y) { 2 }
let(:instance) { described_class.new(x: x, y: y, direction: direction) }
context 'when a L command is issued' do
before do
instance.move('L')
end
subject{ instance.... | true |
224191a2914151eda2d74558825fb5657a9af474 | Ruby | konalegi/eta_calculator | /app/services/car_service.rb | UTF-8 | 918 | 2.84375 | 3 | [] | no_license | class CarService
class ServiceError < BaseServiceError; end
class ArgumentError < ServiceError; end
attr_reader :lat, :lon
def initialize(params = {})
@lat = is_float_valid!('Lattitude', params[:lat])
@lon = is_float_valid!('Longitude', params[:lon])
end
def eta
distance_array = Car.available... | true |
d9569fef430add887aab87d7f15ad929ec88bc01 | Ruby | Cloudxtreme/gutenberg-4 | /spec/markdown_renderer_spec.rb | UTF-8 | 12,655 | 2.640625 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-public-domain-disclaimer"
] | permissive | require_relative 'helper'
require_relative '../lib/gutenberg/markdown_renderer.rb'
describe Gutenberg::MarkdownRenderer do
before do
@style = mock('style')
@style.stubs(:image_for).returns("image")
@hyphen = mock('hyphen')
Text::Hyphen.stubs(:new).returns(@hyphen)
@renderer = Gutenberg::MarkdownR... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.