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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1e1a0e5975304d24a403a5445fb6520b73c68e4a | Ruby | larrytheliquid/methodical | /spec/class_methodize_spec.rb | UTF-8 | 2,983 | 3.140625 | 3 | [] | no_license | require File.join(File.dirname(__FILE__), 'spec_helper')
require File.join(File.dirname(__FILE__), 'fixtures', 'class_with_class_methods')
describe Methodical, "#class_methodize, for class methods" do
before(:each) do
@class = ClassMethods
end
describe "with no parameters" do
it "should return a m... | true |
5b59abb4474ddd25fbcc85cda88a9173a0642958 | Ruby | weyewe/infoss-saas | /app/models/cost.rb | UTF-8 | 1,473 | 2.640625 | 3 | [] | no_license | class Cost < ActiveRecord::Base
validates_presence_of :name
def self.active_objects
self
end
def self.create_object(params)
new_object = self.new
new_object.code = params[:code]
new_object.name = params[:name]
new_object.amount = BigDecimal(params[:am... | true |
3a0232a0020a0de9fae49cbfcad26c2e7e22b386 | Ruby | mushah/Ruby | /ex4.rb | UTF-8 | 588 | 3.78125 | 4 | [] | no_license | class Ex4
cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven
puts "There are #{cars} cars available."
puts "There are only #{driver... | true |
9bdbe561aabf1faef87a26f670104d48e1a283dc | Ruby | thebravoman/software_engineering_2014 | /class004/Denis_Stoinev_Class4_1.rb | UTF-8 | 449 | 2.546875 | 3 | [] | no_license | arry = Array.new(19,0)
i = 0
c = 0
Dir.glob("#{ARGV[0]}/**/*.*") do |my_text_file|
s = my_text_file.split(/_/)
i = s.last.split(/\./).first
if i.length < 3
i = i.to_i
else i = 20
end
if i > 1 and i < 19
arry[i-1] += 1
end
end
for c in 1..17
if c > 16
print "#{c+1}"
else
print "#{c+1}," ... | true |
b610d8ddf25858730fd4287fc94e535b19b837a7 | Ruby | shail/algo | /recursion/group_no_adj.rb | UTF-8 | 314 | 2.703125 | 3 | [] | no_license | def group_no_adj(start, nums, target)
return target == 0 if start >= nums.length
return group_no_adj(start + 2, nums, target - nums[start]) ||
group_no_adj(start + 1, nums, target - nums[start])
end
p group_no_adj(0, [2,5,10,4], 12)
p group_no_adj(0, [2,5,10,4], 14)
p group_no_adj(0, [2,5,10,4], 7)
| true |
32b4af953f87cfe673d0b116bb7ce50275defb86 | Ruby | sunapi386/dupecheckr | /duplicates.rb | UTF-8 | 1,802 | 3.359375 | 3 | [] | no_license | ## Jason Sun <jason@sunapi386.ca>
## Jan 30, 2017
##
## Lists the duplicate files in the two given directories.
## Simple, only compares names. Case sensitive.
## Options:
## - filter by file extension
## - list the non-duplicate files
## - show the list (vs just stats)
require 'optparse'
# Parse
options = {}
OptionP... | true |
524cc56c5ab44cc5f47138d0e0fc4f68ca64d6d5 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/6851.rb | UTF-8 | 292 | 3.21875 | 3 | [] | no_license | class String
def sort
self.chars.sort.join
end
end
def combine_anagrams(words)
anagram_hash = {}
anagram_hash.default=[]
words.each {|word| anagram_hash[word.downcase.sort]+=[word]}
anagrams = []
anagram_hash.each_value { |list| anagrams+=[list] }
anagrams
end
| true |
ec577887ef0685ee6a0e2397dab572a585cc8b19 | Ruby | TallerWebSolutions/flow_climate | /spec/helpers/date_helper_spec.rb | UTF-8 | 2,389 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
RSpec.describe DateHelper do
describe '#time_distance_in_words' do
context 'less than a day' do
it { expect(helper.time_distance_in_words(5000)).to eq "1 #{I18n.t('datetime.date_attributes.hour', count: 1)}" }
end
context 'less than an hour' do
it { expect(helpe... | true |
75d4798757521c4e168eee8f05e02e4b85f76400 | Ruby | tiembo/code_stuff | /codeeval/10/10.rb | UTF-8 | 142 | 3.1875 | 3 | [] | no_license | File.open(ARGV[0]).each do |line|
chars = line.chomp.split(" ")
pos = chars.pop.to_i
next if pos > chars.length
puts chars[-pos]
end
| true |
7afd84eb147554653ef848b1cdb2f0a4bb8b6616 | Ruby | Dancalif/Learning-Ruby | /TA/HW_14/script_14_03.rb | UTF-8 | 118 | 3.796875 | 4 | [] | no_license | # Using 'puts' display the following statement and its result
puts "What is 3 + 2?"
print "3 + 2 is "
puts 3 + 2
| true |
a4edf482d8657026ac3b1104422f235a1d431180 | Ruby | lrharris215/tic_tac_toe | /spec/move_validator_spec.rb | UTF-8 | 766 | 2.765625 | 3 | [] | no_license | describe "move_validator" do
let(:board) { TestBoard.new }
let(:converter) { TestConverter.new }
subject(:validator) { MoveValidator.new(board, converter) }
context "valid_move?" do
it "Accepts valid player input" do
expect(validator.valid?("3")).to be(true)
end
it "Rejects invalid player inp... | true |
cb57f21b689a508427c1a24d67ad323070a2c219 | Ruby | bcpearce/mastermind | /spec/code_spec.rb | UTF-8 | 1,652 | 3.359375 | 3 | [] | no_license | require_relative "../lib/code.rb"
describe Code do
let(:code) { Code.new }
#code.sequence.each{|p| print p; puts}
it "should contain only default colors" do
result = code.sequence.all? { |c| Code.default_colors.member?(c) }
expect(result).to be_truthy
end
describe '#valid?' do
let(:code) { ... | true |
6b69c0d3b1c61defda04f2322e029c231d5d67d2 | Ruby | HideTheMess/academy | /w3d2/question_pairs/question.rb | UTF-8 | 1,937 | 2.875 | 3 | [] | no_license | require './question_database'
require './user'
require './reply'
require './question_follower'
require './question_like'
class Question
attr_reader :id, :title, :body, :author_id
def initialize(question_hash)
@id = question_hash['id']
@title, @body = question_hash['title'], question_hash['body']
@auth... | true |
39e7fbb5e806c736730dfa120821510193070080 | Ruby | MislavGunawardena/Back-End-Lesson01 | /excercises/small_problems_repeat/set1.4/7b.rb | UTF-8 | 266 | 3.375 | 3 | [] | no_license | def hexadecimal_to_integer(str)
value = 0
hex_digits = ('0'..'9').to_a + ('a'..'f').to_a
str.downcase.chars.each { |chr| value = value * 16 + hex_digits.index(chr) }
value
end
p hexadecimal_to_integer('4D9f') == 19871
p hexadecimal_to_integer('510') == 1296 | true |
0d0f906f332e6b934f1eb906612bafa1fb90fda2 | Ruby | pemacy/Launch_School | /Coursework/100/130/Medium1/new.rb | UTF-8 | 669 | 2.765625 | 3 | [] | no_license | require 'spreadsheet'
require 'minitest/autorun'
puts $LOADED_FEATURES.select{|e| e[/minitest.rb/] == 'minitest.rb' }
dir = Dir.pwd
p dir.class
book = Spreadsheet.open('test.xls')
class CompareFiles
def process
@d = Dir.pwd
@files = Dir.entries(@d)
@txt = @files.select { |f| f.end_with?('.txt')}
... | true |
c133307e12e39cd69a8d932f425ed3475c32e9d4 | Ruby | jennifersarahpaul/LHL-W3-stores-and-employees | /lib/store.rb | UTF-8 | 323 | 2.515625 | 3 | [] | no_license | class Store < ActiveRecord::Base
has_many :employees
validates :name, length: {minimum: 3}
validates :annual_revenue_less_than_one
def annual_revenue_less_than_one
if annual_revenue == nil || annual_revenue < 1
errors.add(:annual_revenue, "ERROR: Revenue must be greater than zero.")
end
end
e... | true |
1b64f1224e650cea621e47b5938c00800933c711 | Ruby | ellevalentine/ruby-class-variables-and-class-methods-lab-london-web-career-040119 | /lib/song.rb | UTF-8 | 4,001 | 4.40625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song # Define our Song class
attr_accessor :name, :artist, :genre # when we produce a new song we want each one to have a name, artist and genre - so here we use the accessor to be able to define these three methods and be able to read and write them.
@@count = 0 # setting count to be a class variable - this... | true |
d2ab82c7075f4597a7593b65ce57793f89d70f46 | Ruby | waterlink/return_spy | /lib/return_spy.rb | UTF-8 | 1,220 | 2.71875 | 3 | [
"MIT"
] | permissive | require "return_spy/version"
require "securerandom"
require "return_spy/support"
require "return_spy/decorator"
module ReturnSpy
class << self
def active?
@active
end
def activate!
@active = true
end
def deactivate!
@active = false
end
def without_return_spy
a... | true |
794dabc0eaceb2744ca9fdefec6eab46b1f277af | Ruby | gimaramb/Tarea2 | /tarea2.rb | UTF-8 | 2,743 | 3.59375 | 4 | [] | no_license | require_relative 'Carrera/Camello'
require_relative 'Carrera/Vuelta'
require_relative 'Carrera/Carrera'
#Se lee el archivo
file = ARGV[0]
lines = []
n = 0;
File.readlines(file).each do |line|
lines << line;
end
#Cantidad de Camellos
cantidad_camellos = lines[0] #cantidad camellos
#Código y Nombre Camellos
came... | true |
a6c0b717fbf58a7adf51c83d145127fd94cd4280 | Ruby | jragni/Full-Stack-Software-Journey | /Data_Structures_And_Algos/caeser_cypher.rb | UTF-8 | 1,100 | 4.5625 | 5 | [] | no_license | =begin
given a sentence
remove the first vowel of every element if even
remove last vowel if odd
return string
=end
def cypher(string)
# split the string into words
# loop through each word with index
# if index is odd -> remove first vowel of word
# else ->remove last vowel of word
... | true |
27cf5a4e5f55ac40a630407983fa0cdf30ebe9f6 | Ruby | jaisonerick/twitterWriter | /client/lib/twitter_watcher/twit_serializer.rb | UTF-8 | 655 | 2.703125 | 3 | [] | no_license | module TwitterWatcher
# Transform a Twitter hash into an API Twit json
class TwitSerializer
# Creates a new TwitSerializer. Receive a Twitter hash
def initialize(status)
@status = status
end
# Overrides the to_json method. Returns an API understandable Twit json
def to_json(*args, &block... | true |
adae691467c8c172d695a3db4cce1cf4568a071a | Ruby | coding-sue-true/sparta-rspec | /project_euler/challenge_ID_2/spec/fibonacci_spec.rb | UTF-8 | 484 | 2.984375 | 3 | [] | no_license | require 'fibonacci.rb'
describe FibonnaciSequence do
before(:each) do
@fib = FibonnaciSequence.new
end
it "should print only even numbers for a certain range" do
@fib.even_iterator(1,10)
expect(@fib.sum_total).to eq 30
end
it "should successfully sum the two previous numbers of the sequence" d... | true |
a812fadb5f1155206ed3a931d96b374439d67a00 | Ruby | KenzoM/AppAcademyPrep | /week1/w1d4/lib/02_timer.rb | UTF-8 | 491 | 3.53125 | 4 | [] | no_license | class Timer
attr_accessor :seconds
def seconds(value = 0)
@seconds = value
end
def time_string
hour, temp_min = @seconds.divmod(3600) ##change this to a single responsblity instead
minute, second = temp_min.divmod(60)
not_strings_yet = [hour,minute,second]
answer = not_strings_yet.map do |... | true |
930390a8f2a0aa3a8cf26274ba1e60b54225f944 | Ruby | piqueen1/many_many_airbnb | /lib/guest.rb | UTF-8 | 246 | 3.1875 | 3 | [] | no_license | class Guest
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def self.all_names
all.map do |guest| guest.name end
end
end | true |
df0bd5e9516ca69d1ac260233e15e5a64cedef4b | Ruby | cbrunsdon/battlesnake-ruby | /test/test_move_deserializer.rb | UTF-8 | 1,967 | 2.75 | 3 | [] | no_license | require "minitest/autorun"
require 'slytherin/move_deserializer'
class TestMoveDeserializer < Minitest::Test
def deserializer
json_payload = {
"food"=>[[1, 1]],
"game_id"=>"laughable-recipe",
"snakes"=>[
{"name"=>"seekaybot",
"url"=>"http://192.168.0.14:4567",
"taunt"... | true |
f931b3f708d7d52e9e5ebbd36faab24b80d8b590 | Ruby | phyman/game_center_on_rails | /app/controllers/rps_game_controller.rb | UTF-8 | 796 | 2.96875 | 3 | [] | no_license | class RpsGameController < ApplicationController
MOVES = ['rock', 'paper', 'scissors']
def new
session[:your_score] ||= 0
session[:their_score] ||= 0
session[:player_move] ||= "none yet "
session[:ai_move] ||= "none yet "
session[:result] ||= " Please Play "
end
def create... | true |
1af38bfffe08cdc283159f93678a5b5f187f3d59 | Ruby | olwend/DB_server | /spec/features/server_spec.rb | UTF-8 | 849 | 2.625 | 3 | [] | no_license |
feature 'server' do
scenario 'runs on localhost:4000' do
visit('/')
expect(page.status_code).to eq 200
expect(page).to have_content "Simple Server"
end
scenario 'route set passes query string params to app' do
visit('/set?somekey=a&somevalue=1')
expect(page).to have_content "Set a = 1"
end... | true |
ba77bf55f2faf730c35a32244fcbbc1273a618a7 | Ruby | rems-palyvoda/website_checker | /lib/clients/faraday_client.rb | UTF-8 | 646 | 2.578125 | 3 | [] | no_license | module App
class FaradayClient < BaseClient
HEADERS = %i(url status reason_phrase error).freeze
def run
connection = Faraday::Connection.new(nil, ssl: {verify: false})
connection .get(url)
rescue Faraday::ConnectionFailed => e
e
end
def to_h
@parsed = HEADERS.inject({}){... | true |
907ab56c0ea469bac618fb6b26a520a273e413a2 | Ruby | AlveeM/exercism-ruby | /atbash-cipher/atbash_cipher.rb | UTF-8 | 359 | 3.09375 | 3 | [] | no_license | class Atbash
class << self
ALPHABET_REVERSED = [*'a'..'z'].reverse.join
def encode(plaintext)
plaintext.downcase
.gsub(/\W/, '')
.tr('a-z', ALPHABET_REVERSED)
.scan(/.{1,5}/).join(' ')
end
def decode(ciphertext)
ciphertext.gsub(' ', '').tr('a-z... | true |
369e5e25aff63402269eb877920a7af640610bbd | Ruby | chischaschos/my-euler-solutions | /ruby/problem1.rb | UTF-8 | 125 | 3.0625 | 3 | [] | no_license | result = (1..999).reduce(0) do |sum, element|
sum += element if element % 3 == 0 || element % 5 == 0
sum
end
puts result
| true |
8841cc9ebcb4089c00c93e261e4006bfc08286ac | Ruby | stevenkaras/kasefet | /test/config_test.rb | UTF-8 | 2,080 | 2.625 | 3 | [
"MIT"
] | permissive | require File.expand_path("test_helper", __dir__)
require "kasefet/config"
require "fileutils"
class ConfigTest < Minitest::Test
def setup
@tmpdir = Dir.mktmpdir
@config = Kasefet::Config.new(@tmpdir + "global.json")
@config.load
end
def teardown
FileUtils.remove_entry(@tmpdir)
end
def test... | true |
babeacf2d05da7db4b0779f34f85fc345831f07a | Ruby | mtsmfm/language_server-protocol-ruby | /lib/language_server/protocol/interface/semantic_tokens.rb | UTF-8 | 1,018 | 2.625 | 3 | [
"MIT"
] | permissive | module LanguageServer
module Protocol
module Interface
class SemanticTokens
def initialize(result_id: nil, data:)
@attributes = {}
@attributes[:resultId] = result_id if result_id
@attributes[:data] = data
@attributes.freeze
end
#
# A... | true |
211658726e729d30cc45a9f68f3831fc5759fef4 | Ruby | sleepingkingstudios/stannum | /lib/stannum/constraints/hashes/indifferent_extra_keys.rb | UTF-8 | 1,517 | 3.03125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'stannum/constraints/hashes'
require 'stannum/constraints/hashes/extra_keys'
module Stannum::Constraints::Hashes
# Constraint for validating the keys of an indifferent hash-like object.
#
# When using this constraint, the keys must be strings or symbols, but it does
# not... | true |
cae9545458f8172b61493cdf45f73c5a245ed03a | Ruby | MAPC/datacommon3 | /spec/models/dataset_spec_pending.rb | UTF-8 | 1,871 | 2.625 | 3 | [] | no_license | require 'spec_helper'
describe Dataset do
describe "#all" do
it "returns all available datasets", vcr: true do
# For whatever reason, this isn't returning.
# And while clearly something is wrong, this is not
# the right place for this test.
pending
# expect(Dataset.all).to have_at_... | true |
b972937384759c24d1b5000c1d9fe29f1a561962 | Ruby | EdyCommits/bank_test | /lib/account.rb | UTF-8 | 760 | 3.375 | 3 | [] | no_license | require_relative 'transaction_log'
require_relative 'statement_printer'
class Account
INITIAL_BALANCE = 0
def initialize(transaction_log: TransactionLog.new, statement_printer: StatementPrinter.new)
@balance = INITIAL_BALANCE
@transaction_log = transaction_log
@statement_printer = statement_printer
... | true |
c2809b16d85e8ea88a521d24b28a0f821879a242 | Ruby | abril/abr.io | /lib/abrio/client.rb | UTF-8 | 1,359 | 2.875 | 3 | [
"MIT"
] | permissive | #Client proxy for Abr.io API.
class Abrio::Client
attr_accessor :uri, :login, :key
DEFAULT_PARAMS = {:format => "xml", :version => "1.0"}
#Use the following options to initialize your client:
# [uri] - Default: "abr.io/api/links"
# [login] - Your login from Abr.io. See: http://abr.io/pages/api
# [key]... | true |
58c64d1da6d9fd2afd4682da9fb43d550b23406f | Ruby | danielsdeleo/loadpath-compiler | /rbcompile.rb | UTF-8 | 3,620 | 2.625 | 3 | [] | no_license | require 'pp'
require 'fileutils'
require 'rubygems'
# ==HAX WARNINGS:
# * this does some terrible things, like using a regex to prevent rubygems from
# loading at all. This will be made non-terrible in the future.
# * Dependency resolution is amateur hour. This will also be made non terrible
# in the future.
# ==P... | true |
6eea485ff680f3b26ea28f58e0f83d1baf8deb60 | Ruby | learn-co-students/OO-Auto-Shop-london-web-121018 | /app/models/car.rb | UTF-8 | 170 | 2.515625 | 3 | [] | no_license | class Car
attr_reader :make, :model
def initialize(make, model, classification)
@make = make
@model = model
@classification = classification
end
end
| true |
2b53d9bd0c9550e0f4cbd2b7cebc532fa9723ecf | Ruby | leeourand/urpleP | /statusscroll.rb | UTF-8 | 499 | 3.171875 | 3 | [] | no_license | class Marquee
attr_accessor :status, :buffer_size
def initialize(status = "test", buffer_size = 20)
@buffer_size = buffer_size
@status = status.split("")
end
def print(str)
`purple-remote "setstatus?message=#{str}"`
end
def scroll
loop do
marquee = status[0, buffer_size]
p... | true |
3b8beceee90fc794786c203a4a575afd9f55244b | Ruby | southwolf/tracebin-ruby | /lib/tracebin/custom_instrumentation.rb | UTF-8 | 916 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'tracebin/events'
require 'tracebin/helpers'
module Tracebin
module CustomInstrumentation
class << self
include Tracebin::Helpers
def instrument(identifier)
unless block_given?
raise ArgumentError, 'Tracebin instrumentation must receive a block'
end
start_t... | true |
90c81c2142ddabd0eab7d02dd9fc8c5ea98e1048 | Ruby | agardiner/csv-diff-report | /lib/csv-diff-report/report.rb | UTF-8 | 12,310 | 3.0625 | 3 | [
"BSD-2-Clause"
] | permissive | require 'csv-diff-report/excel'
require 'csv-diff-report/html'
require 'csv-diff-report/text'
class CSVDiff
# Defines a class for generating diff reports using CSVDiff.
#
# A diff report may contain multiple file diffs, and can be output as either an
# XLSX spreadsheet document, or an HTML file.
... | true |
3420635bdd634f3f799bfa7f9b60a8795a27cf51 | Ruby | aarondevon/rbnd-toycity-part2 | /lib/app.rb | UTF-8 | 7,772 | 3.234375 | 3 | [] | no_license | require'pry'
require 'json'
# Grabs info from JSON file and sets up report file to export to.
def setup_files
path = File.join(File.dirname(__FILE__), '../data/products.json')
file = File.read(path)
# Made products_hash a global variable.
$products_hash = JSON.parse(file)
# Made report_file a global variable.
$repor... | true |
10cd39afc02512893edabd07f24252952b9cc058 | Ruby | Tarek-Dinkespiler/kata_algo_skelzor | /spec/lib/technical_test/five_spec.rb | UTF-8 | 382 | 2.578125 | 3 | [] | no_license | describe TechnicalTest::Five do
describe "#perform" do
subject { TechnicalTest::Five.new.perform }
it "has 11 results" do
subject.count.should == 11
end
it "works" do
subject.should include("1 + 2 + 34 - 5 + 67 - 8 + 9")
subject.should include("123 - 45 - 67 + 89")
subject.sh... | true |
919cc85799abe26ee6ce9772484c16ece0ecf716 | Ruby | gonzamvita/RubyLessons | /Day 2/classVariables.rb | UTF-8 | 361 | 3.59375 | 4 | [] | no_license | class Muffin
attr_reader(:color, :flavour, :shop)
@@shop = "Ironhack"
def initialize color, flavour
@color = color
@flavour = flavour
end
def shop #to acces class variables better create a method!
@@shop
end
end
myMuff = Muffin.new("Brown", "Chocolate")
puts "Color: #{myMuff.color}, flavour: ... | true |
491200bbefa95a0789dbf0fad528fd5de16b717c | Ruby | gglin/project-euler | /ruby_all/368.rb | UTF-8 | 1,114 | 4 | 4 | [] | no_license | # Problem 368: A Kempner-like series
# http://projecteuler.net/problem=368
#
# The harmonic series 1
# +12
# +
# 13
# +
# 14
# + ... is well known to be divergent.
#
# If we however omit from this series every term where the denominator has a 9 in it, the series remarkably enough converges... | true |
5efe07d94a322248d5e72ad75c17a50a3f0d25aa | Ruby | UCLeuvenLimburg/apt-course-material | /samples/ruby/sudoku-solver.rb | UTF-8 | 1,211 | 3.328125 | 3 | [] | no_license | Pos = Struct.new :x, :y
def same_row?(p, q)
p.y == q.y
end
def same_col?(p, q)
p.x == q.x
end
def same_sqr?(p, q)
p.x / 3 == q.x / 3 and p.y / 3 == q.y / 3
end
def same_group?(p, q)
same_row?(p, q) or same_col?(p, q) or same_sqr?(p, q)
end
def solve(pairs, solution={})
if pairs.empty?
s... | true |
8e4b86ba57e8fdfc38b2a34832e5e84f367f4e2f | Ruby | Bootchie6/prime-ruby-onl01-seng-pt-100619 | /prime.rb | UTF-8 | 179 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Add code here!
def prime?(number)
if number <= 1
return false
else
(2...number).to_a.all? do |possible_prime|
number % possible_prime != 0
end
end
end | true |
eca5fdee500dc8df19fee50f5ba8cfaf896741ac | Ruby | PeterCamilleri/format_engine | /lib/format_engine/spec_info.rb | UTF-8 | 2,440 | 3.15625 | 3 | [
"MIT"
] | permissive | module FormatEngine
#A little package of info about the engine's progress.
class SpecInfo
#The source data for formatting, string input for parsing.
attr_reader :src
#The destination of the process.
attr_reader :dst
#The formatting engine.
attr_reader :engine
#A hash f... | true |
291741dde507c2613095a2cb6eacf312ff72f209 | Ruby | Zenwa5/square_array-online-web-sp-000 | /square_array.rb | UTF-8 | 110 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
number_2 = []
array.each {|number| number_2 << number**2}
return number_2
end
| true |
2e15e0b8a3ac9ca5f52f1013b7839505e7b3f577 | Ruby | cxn03651/writeexcel | /examples/merge6.rb | UTF-8 | 1,824 | 3.03125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/ruby -w
# -*- coding: utf-8 -*-
###############################################################################
#
# Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
# method with Unicode strings.
#
#
# reverse('©'), December 2005, John McNamara, jmcnamara@cpan.org
#
# original writte... | true |
84b0cba8f961ddc6867bd0693d2dc5c3015193fe | Ruby | KrisD2/ls_challenges | /medium_1/phone_number/phone_number.rb | UTF-8 | 430 | 3.203125 | 3 | [] | no_license | class PhoneNumber
def initialize(phone_number)
@phone_number = phone_number
end
def number
return '0000000000' if invalid_number?
clean_number = @phone_number.gsub(/\D/, '')
clean_number.slice(-10..-1)
end
def invalid_number?
!(@phone_number.gsub(/\W/, '') =~ /^1?[\d]{10}$/)
end
de... | true |
4372d9433fef7b7d1a5f885bb3a9463d9b4a9101 | Ruby | jonathanhaskins08/Tealeaf_Materials | /workbook_exercises_easy_questions.rb | UTF-8 | 6,645 | 4.09375 | 4 | [] | no_license | #Quiz 1
#1) Should print out the numbers of the array with only one copy of each number.
#This does not permanently change the array, therefore the numbers array will still be [1, 2, 2, 3].
#2) When ! is used at the beginning of a method or operator it can sometimes mean "not" or "opposite", such as not equal (!=), an... | true |
73ffce2d170754da66f8516266932f4ebffb030d | Ruby | JulioAcevedo/poker | /poker_game.rb | UTF-8 | 1,005 | 3.625 | 4 | [] | no_license | require_relative "interfaces/user_interface"
require_relative "cards/deck"
require_relative "cards/hand_evaluator"
require_relative "players/player"
class PokerGame
attr_reader :winner
def initialize(how_many_players)
raise Exception.new("Number of players allowed: 1 to 10") unless how_many_players
@deck ... | true |
08e96ef48d34766f6e54cd57c2f991aa792b15ae | Ruby | jessicamurphyma/tts_notes | /Week 2 Ruby and Github/animal_after_github.rb | UTF-8 | 961 | 4.46875 | 4 | [] | no_license | class Animal
attr_accessor :size, :color, :gender, :species, :age, :name
def initialize(size, color, gender, species, age, name)
@size = size
@color = color
@gender = gender
@species = species
@age = age
@name = name
end
def introduction
puts "This animal is a #{@size}... | true |
767ea2ad18e788516b1d3a14ccc1c1160aa8a660 | Ruby | bullrico/compass-facebook | /lib/compass_facebook/sass_extensions.rb | UTF-8 | 207 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'sass'
module Sass::Script::Functions
def enumerate(prefix, from_index, to_index)
Sass::Script::String.new(((from_index.value)..(to_index.value)).map{|i| "#{prefix}#{i}"}.join(", "))
end
end | true |
b06223511339c05e0b1da1941f46bc9d24520dca | Ruby | cppcho/epi-exercises | /5_5_the_power_set.rb | UTF-8 | 755 | 3.5625 | 4 | [] | no_license | def assert(expr)
raise "This is wrong" unless expr
end
def power_set(s)
# v1(s)
v2(s)
end
def v1(s)
result = []
(0...2**s.count).each do |i|
arr = []
(0...s.count).each do |j|
if i >> j & 1 == 1
arr.push(j)
end
end
result.push(... | true |
42cef090be6dceb3d0f739cbb15e7fc2f23d8021 | Ruby | saipat/AA-Daily | /Practices/Assessments/Assessment1/median.rb | UTF-8 | 354 | 4.0625 | 4 | [] | no_license | # Write a method that returns the median of elements in an array
# If the length is even, return the average of the middle two elements
class Array
def median
return nil if self.empty?
return self[0] if self.length == 1
copy = self.sort
mid = copy.length / 2
copy.length.even? ? (copy[mid-1] + cop... | true |
535fdb003c0adf505ad5b369cedfb0bed3727ea8 | Ruby | jbonfante/overlord | /overlord/app/helpers/bomb_helpers.rb | UTF-8 | 2,686 | 2.671875 | 3 | [] | no_license | # File response_format.rb
# encoding: UTF-8
module Sinatra
module BombHelpers
WireResponse = Struct.new(:status, :message)
def create_wires(number_of_wires)
wires = []
speed_down_wire, speed_up_wire, diffusing_wire, detonating_wire = (0..number_of_wires.to_i).to_a.sample(4)
number_of_wires... | true |
0e096f44a8c097c52a4f1730ff060aff78d6a434 | Ruby | akmassey/poppins | /lib/poppins/document.rb | UTF-8 | 4,508 | 3.09375 | 3 | [
"MIT"
] | permissive | require 'securerandom'
require_relative 'reference_link'
require_relative 'inline_link'
module Poppins
class Document
attr_reader :reference_links, :inline_links, :links
def initialize(input=nil, output=nil)
if input.empty?
raise "invalid input" unless (ARGF.respond_to?(:readlines) and not ARG... | true |
3b7c9aea62e918b1d8a5d9bb27a34f02708cc7f0 | Ruby | rpersun/Ruby_Book | /variables/testfile.rb | UTF-8 | 138 | 3.109375 | 3 | [] | no_license |
=begin
x = 0
3.times do
x += 1
end
puts "first output"
puts x
=end
y = 0
5.times do
y += 1
x = y
end
puts "second output"
puts x
| true |
7938924d772c39ca83566ba1586880d78775cc60 | Ruby | func-i/Canlii-Citation-Visualizer- | /lib/capi/database.rb | UTF-8 | 773 | 2.5625 | 3 | [] | no_license | require 'capi/delegate/database_object'
module Capi
module Database
# => List all case databases (230 total)
def list_case_databases
delegate_db_type(@request.get('caseBrowse'))
end
# => List all legislation databases (28 total)
def list_legislations_databases
delegate_db_type(@requ... | true |
744ff36a6d8ca47e9cb28ae7021c36add1a4c954 | Ruby | MalekYmn/RB101 | /lesson_5/sort.rb | UTF-8 | 244 | 3.5625 | 4 | [] | no_license | array = [2, 5, 3, 4, 1]
p array.sort
array = array.sort do |a, b|
b <=> a
end
p array
[2, 5, 3, 4, 1].sort do |a, b|
puts "a is #{a} and b is #{b}"
a <=> b
end
ary = ['cot', 'bedroom', 'aat bat'].sort_by do |w|
w.length
end
p ary
| true |
c47eba681ffdaa5d6e2baf329db88e4e52f97d90 | Ruby | ggonnella/genomeviewer | /script/gt_server.lib/get_hotspots.rb | UTF-8 | 679 | 2.671875 | 3 | [] | no_license | module GT
class ImageInfo
def get_hotspots()
hotspots = []
self.each_hotspot do |x1, y1, x2, y2, fn|
hotspot = []
hotspot[0] = x1
hotspot[1] = y1
hotspot[2] = x2
hotspot[3] = y2
feature = {}
fn.update_attribs
feature[:ID] = fn.get_attribu... | true |
7ddbd45757bc881c1bde5b8fcbcfb9e9953fba98 | Ruby | ksss/digest-stringbuffer | /spec/bench.rb | UTF-8 | 1,042 | 2.75 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'digest/stringbuffer'
require 'benchmark'
module Digest
class BenchClass < Digest::Class
def initialize(*arg)
super
@buf = []
end
def update (arg)
@buf <... | true |
a63f2512fd547ecb894a1c7a338673e23bdee026 | Ruby | ighnatenko/Library | /models/library.rb | UTF-8 | 346 | 2.71875 | 3 | [] | no_license | require_relative "book.rb"
require_relative "order.rb"
require_relative "reader.rb"
require_relative "author.rb"
class Library
attr_accessor :books, :orders, :readers, :authors
def initialize(books = [], orders = [], readers = [], authors = [])
@books = books
@orders = orders
@readers = readers
@a... | true |
ce3615876ea2903af3d302f1b1ba1ab00dc83565 | Ruby | joshlapid/railsweek | /railz/app/controllers/password_controller.rb | UTF-8 | 871 | 2.578125 | 3 | [] | no_license | class PasswordController < ApplicationController
def check
@user_id = params[:userid]
@password = params[:password]
session[:user] = @user_id
@result = "Guess a number."
if (check_username? && check_password?)
render "game/try.html.erb"
else
flash.now[:alert] = "Credentials are inv... | true |
97a20673f3c20695546b914e381c6cbb8db72181 | Ruby | camillerheaumet/module-one-final-project-guidelines | /app/helpers/crime_data.rb | UTF-8 | 654 | 2.6875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CrimeData
def self.get_crimes_for_location(lat, lng)
# this isn't an ideal way of dealing with urls, but it will suffice for the MVP
url = "https://data.police.uk/api/crimes-street/all-crime?lat=#{lat}&lng=#{lng}"
# binding.pry
JSON.parse(RestClient.get(url))
end
def data_search
true_da... | true |
70bba477ab696e553c2766f4b2d4f20ada962215 | Ruby | StructCE/Struct-Trainee-2019-2 | /Assignment 1/Victor/p1ex1.rb | UTF-8 | 134 | 3.375 | 3 | [] | no_license | puts "Digite algo: "
algo = gets.chomp
if algo.ascii_only?
puts "Contem apenas ascii."
elsif
puts "Nao contem apenas ascii."
end
| true |
dbd6c010fa1103831ce6121a998e0686fdd819ed | Ruby | alloy/undercover | /undercover.rb | UTF-8 | 5,622 | 2.625 | 3 | [] | no_license | # Created by Eloy Duran (e.duran@superalloy.nl)
# You can redistribute it and/or modify it under the Ruby's license or the GPL2.
require 'xmlrpc/client'
require 'cgi'
class Cia
SERVER = "cia.vc"
def initialize(data)
@data = data
end
def send_commit_messages!
server = XMLRPC::Client.new(SERVER)
... | true |
13c11e615685884078b853db6424c20f60d1be1f | Ruby | rcasias/ice_cream_shops | /spec/models/shop_spec.rb | UTF-8 | 2,990 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Shop, type: :model do
it {should have_many :flavors}
it 'will return delivery' do
shop = Shop.create(name: "Ice Cream", address: "123", phone_number: "999-999-9999", rating: 4.5, hours_of_operation: "4-9", has_delivery: true)
shop2 = Shop.create(name: "Vamilla", addr... | true |
264662f9386b6e118d7b3a95d1984f0c9efe54f8 | Ruby | CodingSensei19/array-methods-lab-online-web-pt-071519 | /lib/array_methods.rb | UTF-8 | 112 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_include(array, element)
array.include?(element)
end
def (using_sort(array).last).to eq("wow")
end
| true |
7b0c9d55c31543a54d0c5e8b454b4316202fd78c | Ruby | kfcteh/midterm | /lib/feedbackimporter.rb | UTF-8 | 977 | 2.890625 | 3 | [] | no_license | class FeedbackImporter
def teacher?
rand(1..2) == 2
end
def randomRating
rand(1..5)
end
def import
users = User.all
users.each do |user|
puts "Generating Fake Feedback for "+user.first_name+"!"
rand(1..6).times do
rating = randomRating
person_being... | true |
ccb56a43293f7f9f51b2aed01353d5c105980987 | Ruby | Souravgoswami/ruby-masterclass | /Section 8: Methods I/Part6_Calling_a_method_from_another_method.rb | UTF-8 | 268 | 3.734375 | 4 | [
"Unlicense",
"LicenseRef-scancode-proprietary-license"
] | permissive | #!/usr/bin/ruby -w
# Right, a method can be called from another method
def foo(a, b)
a * b
end
def bar(a, b)
a + b
end
def baz(a, b)
foo(a, b) + bar(a, b)
end
p baz(5, 6) # => 41
p baz(10, 10) # => 120
define_method(:qux) { |a| baz(a, a) }
p qux(20)
| true |
d56ca3bb8554ead11aee508772a8a72ed63a5568 | Ruby | mevanoff24/playground | /common/fibonacci.rb | UTF-8 | 125 | 3.609375 | 4 | [] | no_license |
def fibonacci(number)
if number == 0 || number == 1
number
else
number * fibonacci(number-1)
end
end
p fibonacci(6) | true |
beb5c36bd8fbb8fb232e4ba21b9b025790743afb | Ruby | maiyama18/AtCoder | /abc/125/d.rb | UTF-8 | 195 | 2.8125 | 3 | [] | no_license | n = gets.to_i
a = gets.split.map(&:to_i)
if a.select { |x| x < 0 }.size.even?
puts a.map(&:abs).reduce(&:+)
else
min_abs = a.map(&:abs).min
puts a.map(&:abs).reduce(&:+) - 2 * min_abs
end
| true |
90b1c5e3b7cbe07232e9ecc4b361938dfd89dfe6 | Ruby | drnic/vagrant | /lib/vagrant/config.rb | UTF-8 | 5,871 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'vagrant/config/base'
require 'vagrant/config/error_recorder'
module Vagrant
# The config class is responsible for loading Vagrant configurations, which
# are usually found in Vagrantfiles but may also be procs. The loading is done
# by specifying a queue of files or procs that are for configuration, and... | true |
02049096dfe4e2bf7673ba2927b2ec234a211db7 | Ruby | justindelatorre/rb_101 | /small_problems/easy_4/easy_4_8.rb | UTF-8 | 1,451 | 4.8125 | 5 | [] | no_license | =begin
In the previous exercise, you developed a method that converts simple numeric
strings to Integers. In this exercise, you're going to extend that method to
work with signed numbers.
Write a method that takes a String of digits, and returns the appropriate number
as an integer. The String may have a leading + or ... | true |
239d19f9d655944f44b2b0a0f768fb7e7021005d | Ruby | sebastianhahne/rails-longest-word-game | /app/controllers/games_controller.rb | UTF-8 | 640 | 2.84375 | 3 | [] | no_license | require 'open-uri'
require 'json'
class GamesController < ApplicationController
def new
# @letters = (0...10).map { (65 + rand(26)).chr }
@letters = Array.new(10) { ('A'..'Z').to_a.sample }
end
def score
@letters = params[:letters]
@answer = params[:answer].upcase
@api_call = english_word?
... | true |
0fb5845332dd3f2cec96dac6317e6f5bc2c3d3e6 | Ruby | cep104/ruby-collaborating-objects-lab-online-web-ft-081219 | /lib/mp3_importer.rb | UTF-8 | 901 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class MP3Importer
attr_accessor :path
def initialize(path)
@path = path
end
#files gets called by #import and returns an array
#Make sure you only get .mp3
#write code that responds to MP3Importer.new('./spec/fixtures').import
#Dir class
#Dir.for each(pathname) do {|file_nam... | true |
1114e34646290a50b740862e44cba52f98bb6ad2 | Ruby | am52saif/Count-Letters | /countLetters.rb | UTF-8 | 250 | 3.5625 | 4 | [] | no_license | def count_letters(str)
letters = Hash.new(0)
arr = Hash.new{|h,k| h[k]= []}
str.split("").each.with_index do |l,w|
unless l == " "
letters[l] += 1
arr[l].push(w)
end
end
end
count_letters("lighthouse in the house...") | true |
fd7815c40bf5c66120d9b873070d22689450454f | Ruby | enjahova/enjshape | /enjshape/shapes.rb | UTF-8 | 10,044 | 2.90625 | 3 | [
"MIT"
] | permissive |
class Shape
attr_accessor :recnum, :units
def initialize(recnum, units)
@recnum = recnum
@units = units
end
def set_units(units)
@units = units
#puts "in Shape.set_units: @units: #{@units} units: #{units}"
end
end
class Polygon < Shape
#rings is an array of indexes of the startin... | true |
3752155ea7a548e8912f457717a383e2f46cf578 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/roman-numerals/51be54ba8c414091b82f8343d2278e2b.rb | UTF-8 | 1,253 | 3.765625 | 4 | [] | no_license | class Integer
def to_roman
digits_with_exp.each_with_object('') do |(digit,exponent),result|
result << Integer::digit_to_roman(digit,exponent)
end
end
# def to_roman
# decimal = self
# power_of_ten = 1000
# result = ''
# while (decimal >= 1) do
# digit = decimal/power_of_ten
... | true |
457e1755acbc843d9fde12e360bbd0f8369eefb0 | Ruby | alecazaux/training-SE3 | /lib/faireunsalut.rb | UTF-8 | 101 | 3.125 | 3 | [] | no_license | class Faireunsalut
def initialize(who)
@who = who
end
def saluer
"Bonjour, #{@who}"
end
end
| true |
4463dd6c4c2420cc1699b3c03357bbb34987bb83 | Ruby | jbbarth/redmine_datacenter | /test/unit/network_test.rb | UTF-8 | 1,870 | 2.546875 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../test_helper'
class NetworkTest < ActiveSupport::TestCase
def test_should_be_valid
[
{:name => "My network", :address => "192.168.2.0", :netmask => "24"},
{:name => "The return of my network", :address => "192.168.3.0", :netmask => "255.255.255.0"}
].each do |... | true |
cfd1cf49dabc9a748dbda2c2a505e73889dc6c02 | Ruby | DudeMason/Contact_List | /app.rb | UTF-8 | 13,640 | 3.5 | 4 | [] | no_license | require './contact.rb'
require 'io/console'
@users = []
@contacts = []
def intro
puts "Welcome, please login or create an account to view your contact list"
puts "1) Log In"
puts "2) Create Account"
choice = gets.strip.to_i
if choice == 1
login
elsif choice == 2
account_create
else
puts "**... | true |
0eb27501bde611c2681ad97f7f85b9f51c96485a | Ruby | ReinaldoAguilar/AT03_API_test | /DanielMontecinos/assignment_four/exercise_one.rb | UTF-8 | 350 | 3.515625 | 4 | [] | no_license | def return_array
[]
end
def print_first_element(array)
array.first
end
def print_last_element(array)
array.last
end
def print_common_elements(array_one, array_two)
array_one & array_two
end
p return_array
p print_first_element([1, 2, 3])
p print_last_element([1, 2, 3])
p print_common_elements([1, 'a', [1, 2... | true |
46ca363cfd7e59dd5f0f2a2f042af6311d330b89 | Ruby | ga-wolf/WDI9_Homework | /mark_harris/week_04/3-Wed/client.rb | UTF-8 | 314 | 3.953125 | 4 | [] | no_license | class Client
attr_accessor :name, :age, :num_children, :pets
def initialize(name, age, num_children)
@name = name
@age = age
@num_children = num_children
@pets = []
end
def to_s
Rainbow("#{@name} is #{@age} with #{@num_children} children and #{@pets.length} pets").yellow
end
end | true |
3559ef552990265d1f8d6c4fd94e0e991a701555 | Ruby | sambrady0652/poker_checker | /lib/helpers/pretty_printer.rb | UTF-8 | 482 | 3.8125 | 4 | [] | no_license | module PrettyPrinter
VALUES = { 11 => "Jack", 12 => "Queen", 13 => "King", 14 => "Ace" }
SUITS = { "H" => "Hearts", "C" => "Clubs", "D" => "Diamonds", "S" => "Spades" }
def pretty_print(symbol)
symbol.to_s.split("_").map(&:capitalize).join(" ")
end
def prettify_high_card(cards)
max... | true |
16836836e6d162acac1e10fd3a563aaf0634acf3 | Ruby | PBillingsby/reverse-each-word-online-web-pt-100719 | /reverse_each_word.rb | UTF-8 | 213 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def reverse_each_word(string)
new = string.split(' ')
new.each {|n| n.reverse!}
new.join(' ')
end
def reverse_each_word(string)
new = string.split(' ')
new.collect {|n| n.reverse!}
new.join(' ')
end | true |
a1285635e18c2f69f26da683804291b5c56f978a | Ruby | unmanbearpig/unorthodox_sudoku | /spec/sudoku/possibility_board_spec.rb | UTF-8 | 1,645 | 2.890625 | 3 | [] | no_license | require 'spec_helper'
require 'sudoku/game_board'
require 'sudoku/possibility_board'
module Sudoku
RSpec.describe PossibilityBoard do
it "returns the correct unknown values" do
board = GameBoard.new(0, 3, 4, 9, 7, 6, 5, 8, 0,
9, 7, 0, 2, 8, 5, 3, 6, 4,
... | true |
75dea76e2dffe7f0865fe8cd530d95212b5a020a | Ruby | chentianwei411/programming-exercise | /17-array-stats.rb | UTF-8 | 560 | 4.09375 | 4 | [] | no_license | # 使用者不断输入数字存进 Array,最后输出总和、平均、最大值、最小值
arr = []
while (true)
print "请输入数字,结束请直接按 Enter: "
user_input = gets
if user_input == "\n"
break
else
arr << user_input.to_i
end
end
total = 0
max = arr[0]
min = arr[0]
arr.each do |i|
total = total + i
if max <= i
max = i
end
if min >=i
min =... | true |
6fa27565bf0ee911638c40d6b67a64e7817c9d00 | Ruby | YosefLehrer/apis-and-iteration-nyc-web-062419 | /lib/api_communicator.rb | UTF-8 | 814 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'rest-client'
require 'json'
require 'pry'
def get_character_movies_from_api(character_name)
response_hash = JSON.parse(RestClient.get('http://www.swapi.co/api/people/'))
response_hash["results"].map do |results|
if results["name"].downcase == character_name.downcase
results["films"]
end
en... | true |
f86d228d02ae09da8546a2496c5f7a5ad8b0bba1 | Ruby | Fukayanegi/CodeIQ | /kawazoe/spiral_walk.rb | UTF-8 | 1,035 | 3.484375 | 3 | [
"MIT"
] | permissive | def dlog variables, method = ""
if ARGV.include?("-dlog")
tmp = ""
variables.each do |key, value|
tmp += "#{key}: #{value}, "
end
p tmp[0..tmp.length-3]
end
end
n = STDIN.gets.chomp.to_i
# n = 1000000
dlog({:n => n})
class Solver
def self.function_g n
answer = 0
answer_f = function... | true |
6ffb08001cc36e42e8e10f12737b7077aae8b5da | Ruby | danzilio/538-election-forecast-bot | /lib/five_thirty_eight_bot.rb | UTF-8 | 2,479 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'twitter'
require 'nokogiri'
require 'json'
require File.expand_path('../forecast', __FILE__)
class FiveThirtyEightBot
attr_reader :twitter_client, :latest_forecast
def initialize
@twitter_client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
confi... | true |
c99287f98f9c4b920d5d1fdb2dfb53d4d567e98d | Ruby | marcelovbm/Ruby- | /primeirosPassos.rb | UTF-8 | 256 | 3.671875 | 4 | [] | no_license | idade = 24
puts idade.class
idade = "24"
puts idade.class
def plural(palavra)
"#{palavra}s"
end
class String
def plural
"#{self}s"
end
end
puts plural("caneta") #canetas
puts plural("carro") #carros
puts "caneta".plural
puts "carro".plural
| true |
3908fe75274e3a6025fc8a139ebbbeab2e4aed0d | Ruby | swifthand/adalog | /test/unit/simple_logging_adapter_test.rb | UTF-8 | 2,109 | 2.6875 | 3 | [
"BSD-3-Clause"
] | permissive | require 'test_helper'
class SimpleLoggingAdapterTest < Minitest::Test
def setup
@default_repo = Adalog::InMemoryRepo.new
end
def default_repo
@default_repo ||= Adalog::InMemoryRepo.new
end
################################################################################
test "new creates a logg... | true |
56ac865ff031344ab6ad69fa8e3310d44eb5353a | Ruby | feigningfigure/WDI_NYC_Apr14_String | /w01/d02/Declan_Van_Welie/guess_the_number.rb | UTF-8 | 326 | 4.03125 | 4 | [] | no_license | def guess_number(num)
random_number = rand(10)
if random_number == num
puts "Congrats! You guessed it!"
else
puts "Guess again!"
num = gets.chomp.to_i
guess_number(num)
end
end
puts "Guess any number between 1 and 10."
num = gets.chomp.to_i
guess_number... | true |
7e816a364daec9645cfcdd919d4c8f6a6e1d1dfe | Ruby | andrzejsliwa/oop-interface | /lib/interface.rb | UTF-8 | 2,832 | 2.59375 | 3 | [
"MIT"
] | permissive | require "interface/version"
module Interface
UnknownInterface = Class.new(StandardError)
module Abstract
def self.extended(interface)
interface.class_eval do
instance_methods(false).each do |method|
define_method(method) do |*args, &block|
methods = [:super, :method_missing]... | true |
a78bfc752b7f2a5115605600cb68245bf384b629 | Ruby | vsparrow/ruby-object-initialize-lab-bootcamp-prep-000 | /lib/person.rb | UTF-8 | 285 | 3.421875 | 3 | [] | no_license | class Person
def initialize(p_name)
@name=p_name
end
def name
@name
end
end
# Define a Person class in lib/person.rb that provides an #initialize method that accepts an argument for the person's name.
# That argument should be stored within a @name instance variable.
| true |
7a302ab8aa5a05a58e0de4e1cc1de647561a5da0 | Ruby | trwong/appacademyprojects | /week1/w1d1/ghost/game.rb | UTF-8 | 1,796 | 3.625 | 4 | [] | no_license | require_relative 'player.rb'
class Game
attr_accessor :player1, :player2, :fragment, :dictionary, :current_player, :previous_player, :losses
def initialize(player1, player2, fragment = "")
@player1 = player1
@player2 = player2
@fragment = fragment
@dictionary = File.readlines("dictionary.txt").map... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.