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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
62326455299837dc8eb64319bc19505cd4004d33 | Ruby | HarlemSquirrel/jackasset | /lib/jackasset/assets_checker.rb | UTF-8 | 1,677 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
module Jackasset
class AssetsChecker
attr_reader :host, :num_issues, :source_dir
def initialize(host:, source_dir:)
@host = host
@source_dir = source_dir
@num_issues = 0
end
def self.call(host: 'http://localhost:8080', source_dir:)
new(host: hos... | true |
2b41931b87634e68e6048677a9a7e618eb2ab3d8 | Ruby | F-emme1/CodingChallengeC14 | /main.rb | UTF-8 | 3,892 | 3.796875 | 4 | [] | no_license | #A single ticket is $35.00
#Tickets can be purchased in lots of 4 for $112.00
#Cotton candy is sold for $1.25 per serving.
#Curly fries are sold for $2.50 for a small and $4.00 for a large.
#The program should then report each of the following.
puts "Welcome to the Ada State Fair expense calculator."
puts "Please prov... | true |
81200225dbb42e314fa78ea250da575f55bbd6af | Ruby | scott-has/challenge_2 | /lib/order_processor.rb | UTF-8 | 850 | 3.0625 | 3 | [] | no_license | require_relative 'tax'
require_relative 'order'
require 'yaml'
class OrderProcessor
attr_accessor :order_lines, :total_tax, :total_items_cost, :args, :tax
def initialize (args, config_file)
@tax = Tax.new(YAML.load_file(config_file))
@args = args
end
def get_order
@order_lines = Order::OrderReader... | true |
ffc4f51bd9dd6445759b53edd62fdf96d98dc47f | Ruby | sylencecode/axial | /lib/axial/consumers/generic_consumer.rb | UTF-8 | 1,659 | 2.921875 | 3 | [] | no_license | module Axial
module Consumers
class ConsumerError < StandardError
end
class GenericConsumer
attr_reader :publisher
def initialize()
@transmitter_object = nil
@mtransmitter_ethod = nil
@queue = Queue.new
@thread = nil
end
... | true |
6f8066820ce940a75a349d5a18d55acb6f429524 | Ruby | matsueodb/sengu | /app/models/element_value/dates.rb | UTF-8 | 1,378 | 2.921875 | 3 | [
"MIT"
] | permissive | # == Schema Information
#
# Table name: element_value_date_contents
#
# id :integer not null, primary key
# value :datetime
# type :string(255)
# created_at :datetime
# updated_at :datetime
#
#
#== 日付
#
class ElementValue::Dates < ElementValue::DateContent
after_initialize :set_value... | true |
10630682625a0d3ca03704a53edca9024a3655be | Ruby | sandeep-freshdesk/Bootcamp_Programs | /ruby_programs/proc.rb | UTF-8 | 389 | 3.234375 | 3 | [] | no_license | greetings = lambda { puts "hello there!" }
printHello = lambda do
puts "hello world"
end
printHello.call
greetings.call
puts "************"
printHello1 = lambda do |name|
puts "hello #{name}"
end
printHello1.call 'sandeep'
puts "^^^^^^^^^^^^^^"
printHello2 = lambda do |name|
return puts "he... | true |
f4ba81bdc5c6f3661296726c156fbee35a6390f4 | Ruby | roussev/Ruby-Meta-Programming | /34_callable_objects.rb | UTF-8 | 940 | 4.375 | 4 | [] | no_license | p "Proc"
inc = Proc.new {|x| x.succ }
inc.call(2) # => 3
inc.(2) # => 4
p "Lambda"
dec = lambda {|x| x.pred }
dec.class # => Proc
dec.call(2) # => 1
# Ruby provides two Kernel methods to convert a block to a Proc: lambda() and proc()
p "& operator"
def my_method(x, &block)
y = x.succ
yield y
end
my_m... | true |
b1373f6ea6fb8d65c5c2764f4f32029f3983563c | Ruby | andkolbe/chirper-rails | /test/models/chirp_test.rb | UTF-8 | 860 | 2.8125 | 3 | [] | no_license | # test_helper.rb loads the default configuration to run the tests
require "test_helper"
# ChirpTest defines a test case because it inherits from ActiveSupport::TestCase
# ChirpTest has all of the methods available from ActiveSupport::TestCase
class ChirpTest < ActiveSupport::TestCase
# test 'should not save chirp w... | true |
e1dd4c44a5c405dbcdb10dc3838f3ce124c46dec | Ruby | Filmscore88/badges-and-schedules-online-web-prework | /conference_badges.rb | UTF-8 | 463 | 3.828125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(array)
new_array=[]
array.each do |x| x=badge_maker(x)
new_array<<x
end
new_array.each do |x| puts x
end
end
def assign_rooms(array)
new_array=[]
array.each_with_index do |x,index|x= "Hello, #{x}! You'll be assigned to room... | true |
e2a44cf5f761f942c21b394475f04c45bf9825d8 | Ruby | potatoHVAC/hackerrank | /ruby/array_initialization.rb | UTF-8 | 215 | 2.875 | 3 | [] | no_license | #https://www.hackerrank.com/challenges/ruby-array-initialization/problem
#completed Oct 2017
# Initialize 3 variables here as explained in the problem statement
array_2 = [10,10]
array_1 = [nil]
array = Array.new
| true |
4bf9715ed01f28bc6e15a6c2c3cb0786616a20ac | Ruby | Oscartic/student-list | /app/graphql/mutations/add_list_mutation.rb | UTF-8 | 881 | 2.546875 | 3 | [] | no_license | module Mutations
class AddListMutation < Mutations::BaseMutation
argument :rut, String, required: false
argument :first_name, String, required: false
argument :last_name, String, required: false
argument :course, String, required: false
argument :number_list, Integer, required: false
argument ... | true |
08d23449a62c2f4b93a13075d9bd0a535619b07e | Ruby | zhzyc142/billionstech_crawl | /lib/billionstech_crawl/sogou.rb | UTF-8 | 5,425 | 2.5625 | 3 | [] | no_license | require 'set'
require 'net/http'
require 'nokogiri'
require 'faraday'
require 'timeout'
require 'pry'
require 'uuidtools'
module BillionstechCrawl
module Sogou
class Crawler
# Set of all URIs which have been crawled
attr_accessor :crawled
# Queue of URIs to be crawled. Array which acts as a FIFO... | true |
936222d77573949b73874513647644c7b54c0a0f | Ruby | warrenshen/blockterm | /server/app/helpers/mention_total_count.rb | UTF-8 | 421 | 3.0625 | 3 | [] | no_license | class MentionTotalCount
def initialize(timestamp)
@timestamp = timestamp
@total_count = 0
self
end
def increment_by(increment)
@total_count += increment
end
def max_by(count)
@total_count = [@total_count, count].max
end
def set_by(count)
@total_count = count
end
def count
... | true |
87c79a825a67bddd23e4ddb63b033b46b8369cb1 | Ruby | cbeer/KriKri | /lib/krikri/parser.rb | UTF-8 | 6,393 | 3.296875 | 3 | [
"MIT"
] | permissive | module Krikri
##
# Provides a generic interface for accessing properties from OriginalRecords.
# Implement the interface, and that of `Value` on an record-type basis.
#
# parser = Krikri::Parser::MyParser.new(record)
# parser.root # => #<Krikri::MyParser::Value:0x007f861888fea0>
#
class Parser
a... | true |
b17391da291e1c829dc891e9f16d42b059ba08c9 | Ruby | bogdanRada/ruby-gem-downloads-badge | /config/initializers/enumerable.rb | UTF-8 | 1,553 | 3.140625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# extending enumerable with methods
module Enumerable
# Sorts gem versions
#
# @return [Array] Array of versions sorted
# @api public
def version_sort
sort_by do |key, _val|
gsub_factory_versions(key)
end
end
# tries to parse a version and returns an array of ... | true |
90815fca1234456a78f66d8e543b8bcb0c121768 | Ruby | code4mk/ruby4you | /ruby_code/z_compiler-design/change_underscore_w_vowel.rb | UTF-8 | 706 | 3.0625 | 3 | [] | no_license | # @code4mk kaaml_ie_t => 4 uniq combination (_=> uniq previous vowel)
your_string = gets.chomp()
b = []
b = your_string.split(//)
count = 1
# loop store_string
b.each_with_index {|val, index|
if val == "_"
previous_datas = 0
previous_v = 0
store_vowel = []
while previous_datas < index
check_po... | true |
3dc7eeaab64eedacdfef971958c55005ea4ef38f | Ruby | jessecalton/phase-0-tracks | /ruby/hashes.rb | UTF-8 | 1,522 | 3.890625 | 4 | [] | no_license | # Ask client information:
# Name
# Age
# Number of Children
# Decor Theme:
# Convert user info to appropriate data type
# Print out the hash to the screen when the user has answered all the questions
# Ask the user if they want to update any of the keys (i.e. :decor_theme)
# Have them type “none” if there are... | true |
78af78ddf80b508a2be26b1d873999feba42f05f | Ruby | zendesk/mail | /tasks/corpus.rake | UTF-8 | 3,247 | 2.671875 | 3 | [
"MIT"
] | permissive | namespace :corpus do
task :load_mail do
require File.expand_path('../../spec/environment', __FILE__)
require 'mail'
end
# Used to run parsing against an arbitrary corpus of email.
# For example: http://plg.uwaterloo.ca/~gvcormac/treccorpus/
desc "Provide a LOCATION=/some/dir to verify parsing in bul... | true |
ba6bcca603d94c8169395f1edb35db3378a9b061 | Ruby | Marygemidzhian/homework | /homework2/hash2.rb | UTF-8 | 208 | 2.96875 | 3 | [] | no_license | arr = (10...36).map{ |i| i.to_s 36}
hash = {
a: arr.find_index('a')+1,
e: arr.find_index('e')+1,
i: arr.find_index('i')+1,
o: arr.find_index('o')+1,
u: arr.find_index('u')+1
}
puts hash
| true |
9f625f61f6045c1065dc9f9cb378629a2cf56f6a | Ruby | ryan-chambers/wine-guide | /lib/wine_score_exporter.rb | UTF-8 | 1,833 | 3.046875 | 3 | [] | no_license | require 'country.rb'
require 'wine.rb'
require 'winery.rb'
class WineScoreExporter
def create_wine_sentence(wine, winery)
# p "create sentence for wine #{wine}"
s = [winery.name.gsub('.', ''), wine.grape.name, wine.year]
s << wine.other.gsub('.', '') unless wine.other.nil? or wine.other.empty?
s << ... | true |
fb4be851b55b74d7de5167f6c366c590144fbe45 | Ruby | nzifnab/budget | /app/models/quick_fund.rb | UTF-8 | 1,387 | 2.765625 | 3 | [] | no_license | class QuickFund < ActiveRecord::Base
# The base account that the quick fund was made from,
# even if overall funds were taken from several sources.
belongs_to :account, inverse_of: :quick_funds
has_many :account_histories, inverse_of: :quick_fund
validates :amount, presence: {message: "Required"}
validates... | true |
d81579d9720c9bfed5fc8d139a6fb6d840ee1eb7 | Ruby | jhogrefe/2015-02-03-mini-programs | /word-connector.rb | UTF-8 | 927 | 3.453125 | 3 | [] | no_license | require 'pry'
require 'active_support'
require 'active_support/core_ext/array/conversions'
# Public: WordConnector class
# Connects an array of strings into a single sentence with an "and"
# between the last two strings using the Active Support .to_sentence
# array conversion.
#
# Attributes:
# None.
#
# Methods:
# #m... | true |
5f1586f0c8171a36de5e6e344ae18f61c7a9a43d | Ruby | gbarka2/intro_to_ruby | /dojo.rb | UTF-8 | 2,799 | 3.96875 | 4 | [] | no_license |
class Fighter
attr_reader :name
attr_accessor :defense, :strength, :luck, :life
def initialize(name, defense, strength, luck, life)
@name = name
@defense = defense
@strength = strength
@luck = luck
@life = life
end
def attack(opponent)
damage = @strength - opponent.defense
if... | true |
902ae462b539b9ba5b08e2c2d7d66b8a1f54b228 | Ruby | jonsjava/random | /balancer.rb | UTF-8 | 697 | 3.046875 | 3 | [] | no_license | require 'optparse'
options = {}
OptionParser.new do |parser|
parser.banner = 'Usage: balancer.rb [OPTIONS]'
parser.on('-i', '--input-hash NAME', 'Username for liquibase admin') do |liquibase_admin|
options[:liquibase_admin] = liquibase_admin
end
end
def balancer(input_a)
unless input_a.hash?
puts "I... | true |
43f9f7115dc1066aafde945fd51272a3d60e0a0a | Ruby | tkyktkmt/furima-34283 | /spec/models/user_spec.rb | UTF-8 | 5,432 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe '#create' do
before do
@user = FactoryBot.build(:user)
end
it 'nickname、first_name、last_name、first_name_katakana、last_name_katakana、birthday、email、passwordとpassword_confirmationが存在すれば登録できること' do
expect(@user).to be_valid
... | true |
436272886c61d9dc67354e4e0afb28f17f59d03c | Ruby | chipcoiga/rubylearn | /gettingmodule.rb | UTF-8 | 773 | 3.515625 | 4 | [] | no_license | #define Perimeter module
module Perimeter
class Array
def initialize
@size = 400
end
end
end
our_array = Perimeter::Array.new
ruby_array = Array.new
#to know about: p/puts/to_s/inspect/print
p our_array
puts our_array
p ruby_array
puts our_array
print our_array
puts our_array
#troll lv max :v
puts "nha toi"... | true |
b1be0ff9c8f0a1bbf7ac1ea30f7831f851284ddf | Ruby | jono/sunstone | /test/sunstone/parser_test.rb | UTF-8 | 3,797 | 2.625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class TestParserModel < Sunstone::Model
belongs_to :test_parser_model
has_many :test_parser_models
define_schema do
integer :testid
boolean :red
datetime :created_at
decimal :rate
string :name
string :nicknames, :array => true
end
end
class S... | true |
f576c935a72cf7f21543d046bbb779a877fd6dac | Ruby | ggk1017/ruby | /labs/lab_buddies.rb | UTF-8 | 673 | 3.578125 | 4 | [] | no_license | require 'pry'
sample = %w{Adrian Derrick Larry Jasmine Raymond Dustin Aaron Chris Zahra Gaurav Audric Avinash Jon Derrick Tim Chang Marc Thomas}
sample_length = sample.length
starting_index = 0
user_prompt = "how many people in a group"
puts user_prompt
group_size = gets.to_i
ending_index = group_size - 1
ne... | true |
442df6da4d12d5fe57fd477051a234d96bcb5518 | Ruby | guns/haus | /bin/vimtabdiff | UTF-8 | 536 | 2.59375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# Copyright (c) 2022 Sung Pae <self@sungpae.com>
# Distributed under the MIT license.
# http://www.opensource.org/licenses/mit-license.php
require 'shellwords'
def vimdiffcmd a, b
"edit #{b.shellescape} | diffthis | vsplit #{a.shellescape} | diffthis | tabnew"
end
if ARGV.empty? or ARGV.size.... | true |
14b6aa106b0c5aefba799d3d43b83674b2cee3aa | Ruby | wwkk08/array-CRUD-lab-v-000 | /lib/array_crud.rb | UTF-8 | 570 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
my = []
end
def create_an_array
my = ["1","2","3","5"]
end
def add_element_to_end_of_array(array, element)
array << element
end
def add_element_to_start_of_array(array, element)
array.unshift(element)
end
def remove_element_from_end_of_array(array)
array.pop
end
def remove_e... | true |
4ce329033789cc57cf29e0ba29c354703e3aedad | Ruby | stevejc/learn-ruby | /week3ex10.rb | UTF-8 | 85 | 3.296875 | 3 | [] | no_license | collection = [1,2,3,4,5]
sum = 0
collection.each do |add|
sum += add
end
puts sum | true |
15d06c9ffbab24d7365b3d8469592dbe8597639a | Ruby | rlisowski/phrase-ruby | /lib/phrase/api/accounts_api.rb | UTF-8 | 5,524 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'cgi'
module Phrase
class AccountsApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Get a single account
# Get details on a single account.
# @param id [String] ID
# @param [Hash] opts the optional parameters
# @... | true |
d596e449add841b2fde84c5c4f7a9c9dba95f25a | Ruby | stefanpenner/rails | /actionpack/lib/action_dispatch/middleware/callbacks.rb | UTF-8 | 1,696 | 2.5625 | 3 | [
"MIT"
] | permissive | module ActionDispatch
# Provide callbacks to be executed before and after the request dispatch.
#
# It also provides a to_prepare callback, which is performed in all requests
# in development by only once in production and notification callback for async
# operations.
#
class Callbacks
include ActiveS... | true |
72f6a8dc442977570b8f2fa6f84820fb0692a6e6 | Ruby | ffloyd/goldfinger | /app/models/concerns/with_amount.rb | UTF-8 | 341 | 2.65625 | 3 | [] | no_license | module WithAmount
extend ActiveSupport::Concern
def amount
# 1. зачем здесь второй аргумент в #new? Для Integer-конвертации он не нужен. Вообще можно так: BigDecimal(10)
# 2. зачем @amount?
@amount = rounded(BigDecimal.new(amount_cents, 4) / 100)
end
end
| true |
d6a94d6e3ba91274ccf350be6750a0fba5f98363 | Ruby | jk1dd/exercism | /ruby/raindrops/raindrops.rb | UTF-8 | 1,172 | 3.0625 | 3 | [] | no_license | class Raindrops
def self.convert(dropz)
phrase = []
if dropz % 3 == 0
phrase << "Pling"
end
if dropz % 5 == 0
phrase << "Plang"
end
if dropz % 7 == 0
phrase << "Plong"
end
if dropz % 3 != 0 && dropz % 5 != 0 && dropz % 7 != 0
phrase << dropz.to_s
end
... | true |
059efffccfd0498aaa9da8e9adaea49f5ba8895a | Ruby | rozz120/ttt-6-position-taken-rb-bootcamp-prep-000 | /lib/position_taken.rb | UTF-8 | 157 | 3.28125 | 3 | [] | no_license | def position_taken?(array,index)
if array[index] == " " || array[index] == "" || array[index] == nil
return false
else
return true
end
end | true |
25108a04206b99fb57500b5fa1478cafc7674917 | Ruby | XochitlX/Objetoss | /miercoles/twitter.rb | UTF-8 | 1,673 | 2.953125 | 3 | [] | no_license | #require 'rubygems'
require 'nokogiri'
require 'open-uri'
class TwitterScrapper
def initialize(url)
@url = url
@page = Nokogiri::HTML(open("#{@url}"))
end
def extract_username
profile_name = @page.search(".ProfileHeaderCard-name > a")
profile_name.first.inner_text
end
def extract_tweets... | true |
19bee26e77a0adb32f03b6521448dc8998700156 | Ruby | cakeholeDC/oo-relationships-practice | /app/models/lyft/passenger.rb | UTF-8 | 538 | 3.296875 | 3 | [] | no_license | class Passenger
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def rides
Ride.all.select do |ride|
ride.passenger == self
end
end
def count_rides
self.rides.count
end
def drivers
drivers = self.rides.map do |ride|
ride.driver... | true |
910af0dd9d5e2da0ceec0cee92bfdcaf6f23cae8 | Ruby | enrikacreates/bewd-hw | /hw03/mash_app/mash.rb | UTF-8 | 894 | 2.59375 | 3 | [] | no_license | require 'sinatra'
require 'httparty'
url = "http://mashable.com/stories.json"
results = HTTParty.get(url)
# page1
get '/' do
@stories = results
erb :home
end
# page2
get '/sort' do
@feed_pick = params['feed']
@articles = results[@feed_pick]
erb :sort
end
# page3
get '/results' do
... | true |
9f0b0f87df4cb199ddd3f2daa614d7b1e052dbd4 | Ruby | montehoover/ruby-rio-grande | /starter-code/spec/digitalitem_spec.rb | UTF-8 | 1,890 | 3.1875 | 3 | [] | no_license | require_relative 'spec_helper'
require_relative '../lib/DigitalItem'
describe DigitalItem do
before(:context) do
#initialize item
@digital_item = DigitalItem.new "DigItem title", 6.99
end
#check initialization
describe "initialization" do
#check that it is an extended from Item
it "extend fro... | true |
32ee9252985f516f387f08fdeadd2f0bb63f47b0 | Ruby | evilbunnyrabbits/programming-univbasics-4-simple-looping-lab-nyc01-seng-ft-062220 | /lib/simple_loops.rb | UTF-8 | 525 | 4.0625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Write your methods here
def loop_message_five_times(message)
count = 0
while count < 5 do
puts message
count += 1
end
end
def loop_message_n_times(message, number)
count = 0
while count < number do
puts message
count += 1
end
end
def output_array(array)
index = 0
while index <= arra... | true |
cbe6d8fa33f6b1f76413cbc95057227046da840a | Ruby | BJSherman80/Adopt_dont_shop_2008 | /spec/features/applications/show_spec.rb | UTF-8 | 4,767 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe 'On an Applications show page the user', type: :feature do
before(:each) do
@user1 = User.create!(name: 'Dr. Evil',
address: '56774 FLower Ave.',
city: 'Smallville',
state: 'Alaska',
... | true |
879db4b1e1378870678463b8c5a762057e9387d7 | Ruby | janicejiang/programming-exercise | /06-interger-positive.rb | UTF-8 | 353 | 4.40625 | 4 | [] | no_license | # 题目: 输入一个数字 x,请判断是否正数、零或负数,以及是不是偶数
print "请输入一个整数,然后按 Enter: "
x = gets.to_i
if x % 2 == 0
puts "这个数是偶数"
else
puts "这个数是奇数"
end
if x < 0
puts "这个数是负数"
elsif x == 0
puts "这个数是零"
else
puts "这个数是正数"
end
| true |
529819638a43a67744e8bc0ed25e62abbeb37e45 | Ruby | entropie/ralpha | /lib/ralpha/pods.rb | UTF-8 | 2,196 | 2.546875 | 3 | [] | no_license | #
#
# Author: Michael 'entropie' Trommer <mictro@gmail.com>
#
module Ralpha
class Pods < Array
attr_reader :query
def subpods
self.map{|pod| pod.subpods }.flatten
end
def initialize(query)
@query = query
super()
end
end
class SubPods < Array
attr_reader :pod
... | true |
65f55a6f777ccaf3daba9d86268daa0d4b9ef966 | Ruby | grantcottle/kovid | /lib/kovid/cli.rb | UTF-8 | 1,544 | 2.921875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'thor'
require 'kovid'
module Kovid
class CLI < Thor
FULL_FLAG = %w[-f --full].freeze
desc 'define', 'Defines COVID-19'
def define
puts Kovid.whatis
end
desc 'check COUNTRY or check "COUNTRY NAME"', 'Returns reported data on provided country. eg: "ko... | true |
bcf7ac2bf6d6fb4aff742a528bade06d025c4998 | Ruby | ashes-ashes/W4D3 | /Chess/piece_types/steppable.rb | UTF-8 | 253 | 2.578125 | 3 | [] | no_license | module Steppable
def moves
new_moves = move_diffs.map do |move|
[move[0] + pos[0], move[1] + pos[1]]
end
new_moves.select { |step| board.valid_pos?(step) && board[step].color != color }
end
private
def move_diffs; end
end | true |
1660e357f1a8fe4f83c0ea03a6fab4143d667430 | Ruby | rbosse/cloudfoundry-buildpack-java | /spec/language_pack/xml_wrapper_spec.rb | UTF-8 | 1,985 | 2.890625 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-other-permissive",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"GPL-2.0-only",
"Apache-2.0",
"Ruby"
] | permissive | require 'spec_helper'
describe XmlWrapper do
let(:xml) { xml = XmlWrapper.new("<doc><name>Tom</name><job>Programmer</job><name>Agnes</name></doc>") }
it "finds a node" do
expect(xml.first("/doc/name").text).to eq "Tom"
expect(xml.first("/doc/job").text).to eq "Programmer"
end
it "returns empty arrays... | true |
1961d04276b3ec8c1b59cc4c7ed54215b0af0e61 | Ruby | evrone/casbin-ruby | /lib/casbin-ruby/model/policy.rb | UTF-8 | 4,200 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
require 'logger'
module Casbin
module Model
class Policy
attr_reader :model, :logger
def initialize(logger: Logger.new($stdout))
@model = {}
@logger = logger
end
# initializes the roles in RBAC.
def build_role_links(rm_map)
re... | true |
21dce1795105e46c9da8c449d8c97e55a6f4e6d6 | Ruby | jayywolff/pokedex | /app/deserializers/pokemon_deserializer.rb | UTF-8 | 1,023 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
class PokemonDeserializer < BaseDeserializer
def deserialize(pokemon_species = nil)
if pokemon_species.present?
build_pokemon_with_species_attributes(pokemon_species)
else
build_pokemon
end
end
def required_keys
[:id, :name, :height, :weight, :sprites, :... | true |
7dfa42d24d61aa3767cc51e6e610111a5d93a20e | Ruby | lbluefishl/hangman | /lib/hangman.rb | UTF-8 | 3,244 | 3.828125 | 4 | [] | no_license |
$file_data = File.readlines("5desk.txt", chomp: true)
require 'json'
class Hangman
def initialize
@guesses = 7
@used_letters = []
@random_word = $file_data.sample.split("")
@hidden_word = " _" * @random_word.length
@save_file = ""
end
def variables
{
guesses: @guesses,
use... | true |
7684a316697c5642c68126ab356e28884bb0326a | Ruby | kaoritorikai23/genba_rails | /1_5_2_2.rb | UTF-8 | 178 | 2.90625 | 3 | [] | no_license | module Chatting
def chat
"hello"
end
end
module Weeping
def weep
"しくしく"
end
end
class Human
include Chatting
include Weeping
end | true |
b97697163e211b5857504e15ef9033d05c2d566e | Ruby | decal/zap-attack | /bin/header-names | UTF-8 | 479 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
# coding: utf-8
#
# Form a unique list of case-insensitive names from HTTP response header fields
#
require 'zap_attack'
include ZapAttack, ZapAttack::API, ZapAttack::Data
headers = Params.new
headers.select! do |h|
h['type'].eql?('header')
end
names = []
headers.each do |h|
aname = h['n... | true |
f0ee2da15c386443140daf41fcae6000ada4be33 | Ruby | PeterCamilleri/fOOrth | /lib/fOOrth/compiler/source.rb | UTF-8 | 1,403 | 2.890625 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require_relative 'source/read_point'
#* compiler/source.rb - The abstract source class shared by many code sources.
module XfOOrth
#The Source class used to contain code common to most sources.
class AbstractSource
include ReadPoint
#Initialize the abstract base class.
de... | true |
19bd8f000c937fff3c74dce1beb499eb28e61828 | Ruby | bharris62/Exercises_easy1 | /e2.rb | UTF-8 | 685 | 4.59375 | 5 | [] | no_license | # Write a method that takes one argument in the form of an integer or a float; this argument may be either positive
# or negative. This method should check if a number is odd, returning true if its absolute value is odd. Floats should
# only return true if the number is equal to its integer part and the integer is odd.... | true |
e9e93326a25eb2c74b5c152ea8ec21ebce58b058 | Ruby | michaelrizzo2/Ruby-Development | /7loops.rb | UTF-8 | 555 | 3.578125 | 4 | [] | no_license | #!/usr/bin/ruby
#This will show all of the alternative while sytaxes in ruby(i hope)
$hours_asleep=0
def tired
if $hours_asleep>=8 then
$hours_asleep=0
return false
else
$hours_asleep+=1
return true
end
end
def snore
puts "Snore"
end
def sleep
puts "z"*$hours_asleep
end
#This is a single line while loo... | true |
203dd0dc067b03a7b745ec8b7a96d3b1080024cd | Ruby | jadamduff/sb_bracketeer | /lib/sb_bracketeer/team.rb | UTF-8 | 634 | 3.375 | 3 | [
"MIT"
] | permissive | # Bracket -> Round -> Game -> TEAM
class SbBracketeer::Team
attr_accessor :name, :score, :roster, :game
def initialize(name, score, game)
@name = name
@score = score
@game = game # Creates a has_one relationship to the Game.
# Continues calling parent objects until the Bracket is reached.
# =>... | true |
5acc8607cac2c24629c360d5e41d4a7cb981d5e4 | Ruby | ma2gedev/chrono_logger | /lib/chrono_logger.rb | UTF-8 | 4,000 | 2.828125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require "chrono_logger/version"
require 'logger'
require 'pathname'
# A lock-free logger with timebased file rotation.
class ChronoLogger < Logger
# @param logdev [String, IO] `Time#strftime` formatted filename (String) or IO object (typically STDOUT, STDERR, or an open file).
# @example
#
# ChronoLogger.ne... | true |
f1fed85fd3f553188d0b7ca6ae4fa8146e332adf | Ruby | TimCummings/launch_school | /109-ruby_and_general_programming/easy_1.rb | UTF-8 | 3,104 | 4.25 | 4 | [] | no_license | # easy_1.rb
# # Repeat Yourself
# def repeat(string, number)
# number.times { puts string }
# end
# # repeat("hello", 3)
# # Odd
# def is_odd?(num)
# num % 2 != 0 && num == num.to_i
# end
# # better solution (provided):
# num % 2 == 1
# puts is_odd?(2) # => false
# puts is_odd?(5) # => true
# puts is_o... | true |
86c2bb7220345b715f4d5eef4752f4ea62e54ce5 | Ruby | voltagead/OpenSplitTime | /app/services/live_time_row_importer.rb | UTF-8 | 3,500 | 2.609375 | 3 | [
"MIT"
] | permissive | class LiveTimeRowImporter
def self.import(args)
importer = new(args)
importer.import
importer.returned_rows
end
def initialize(args)
ArgsValidator.validate(params: args,
required: [:event, :time_rows],
exclusive: [:event, :time_rows],
... | true |
05f9026546787fd310b3fb7baa4b85edba9588d1 | Ruby | mulhoo/grocery-store | /lib/customer.rb | UTF-8 | 796 | 3.296875 | 3 | [] | no_license | require 'csv'
class Customer
attr_reader :id
attr_accessor :email, :address
def initialize (id, email, address)
@id = id
@email = email
@address = address
end
def self.all
customer_csv = CSV.read("data/customers.csv")
all_customers = []
customer_csv.each do |info|
id = info[0... | true |
2885c160c7941f26b00901642a2a46af34b17a46 | Ruby | TonyCTHsu/LeetCode | /Easy/AddDigits.rb | UTF-8 | 402 | 3.984375 | 4 | [] | no_license | # Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
# For example:
# Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
# @param {Integer} num
# @return {Integer}
def add_digits(num)
sum=0
if num<10
return num
... | true |
54db8620d894c66f9d391eb50f42226560c6c92e | Ruby | EngSwCIC/Athene | /features/step_definitions/autenticacao/login_steps.rb | UTF-8 | 1,100 | 2.515625 | 3 | [] | no_license | def buildloginUser
@user = User.find_by nick:'teste'
if !@user.nil?
@user.destroy
end
@user = User.new(nick:'teste', senha:'teste123456', email:'teste@gmail.com')
@user.save!
end
def unbuildloginUser
page.driver.browser.clear_cookies
@user.destroy unless @user.nil?
end
Given("eu esteja na pagina de ... | true |
c4daf9d01d89bebd0808e9d417e7a4448cb63ecc | Ruby | rs-pro/russian_inflect | /lib/russian_inflect/dictionary.rb | UTF-8 | 2,409 | 3.140625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module RussianInflect
UnknownError = Class.new(StandardError)
class UnknownCaseException < UnknownError
def initialize(gcase)
super "Unknown grammatical case: `#{gcase}'."
end
end
class UnknownRuleException < UnknownError
def initialize(word)
super "Can't... | true |
8e4b05b39d562af14164c355732eac31ee03ff80 | Ruby | JohnDowson/adventofcode2019 | /day_8/solution.rb | UTF-8 | 534 | 3.296875 | 3 | [] | no_license | def get_layers(wsize, hsize)
IO.read('./input.txt').split('').map(&:to_i).each_slice(wsize).each_slice(hsize).map(&:flatten)
end
pp 'Star 1'
# [1] because there's a loose 0 at the end of input for some reason
get_layers(25, 6).sort { |a, b| a.count(0) <=> b.count(0) }[1].then { |l| p l.count(1) * l.count(2) }
pp 'St... | true |
6207fe22dcec7cf281d678b9dc1fe4d3e0b8d2a6 | Ruby | Proskurina/learn_to_program | /ch09-writing-your-own-methods/old_school_roman_numerals.rb | UTF-8 | 257 | 2.9375 | 3 | [] | no_license | def old_roman_numeral num
roman_num = ""
roman_num << "M"*(num/1000)
roman_num << "D"*(num%1000/500)
roman_num << "C"*(num%500/100)
roman_num << "L"*(num%100/50)
roman_num << "X"*(num%50/10)
roman_num << "V"*(num%10/5)
roman_num << "I"*(num%5)
end | true |
d5acda77b122abea0ee2f160c1dd485c5df98de0 | Ruby | athar4228/toy_robot | /spec/toy_robot_robot_spec.rb | UTF-8 | 4,219 | 2.828125 | 3 | [] | no_license | require 'toy_robot/table'
require 'toy_robot/robot'
RSpec.describe "ToyRobot:Robot" do
let(:table) { ToyRobot::Table.new }
subject { ToyRobot::Robot.new(table) }
describe 'initialise Robot' do
it 'should set value of table' do
expect(subject.table.instance_of? ToyRobot::Table).to eq(true)
end
e... | true |
aed0b5011c691b8cbd1930e6788bac0b8ce2f882 | Ruby | JiriKrizek/MI-RUB-sem | /lib/tags/table_node.rb | UTF-8 | 597 | 2.765625 | 3 | [] | no_license | module HTML
module Tags
class TableNode < Tag
def initialize(tag)
super(tag.tag, tag.attr)
fail HTML::InvalidTagError.new("Invalid attributes in tag #{@tag}") unless valid_attributes?
end
def valid_attributes?
valid=Set.new ["border", "cellpadding", "cellspacing",... | true |
dce5806c3abd78532e1e295af5584b635b3d33fb | Ruby | raquelnishimoto/ruby_intro | /intro_to_programming/flow_control/flow_control_5.rb | UTF-8 | 654 | 4.84375 | 5 | [] | no_license | # program that takes a number from the user between 0 and 100
# and reports back whether the number is between 0 and 50, 51 and 100, or above 100
# using a case statement
# limitation - it will convert any string e.g. "abc" to an integer.
def report(number)
result = case
when ((number >= 0) && (number <= 50))
"#{... | true |
e8ebdf63a8cc283e332e9a481a1993fc040efcb2 | Ruby | ASL20/tasks | /06_05/2_1.rb | UTF-8 | 181 | 3.296875 | 3 | [] | no_license | word = "Everybody"
index = 0
while index < word.length
puts word[index].upcase
index += 1
end
index = 0
until index == word.length
puts word[index].upcase
index += 1
end
| true |
8fabdbe2bfe455f0b4afb330b49f12efb76aaa64 | Ruby | timgaleckas/gosu_tetris | /lib/colors.rb | UTF-8 | 1,028 | 2.5625 | 3 | [] | no_license | module Colors
def self.from_hex(hex_string)
Gosu::Color.new(*hex_string[1..-1].scan(/.{2}/).map{|s|s.to_i(16)})
end
FG = "#000022"
MENU_BACKGROUND_HEX = "#DDDDBB"
MENU_BACKGROUND = from_hex(MENU_BACKGROUND_HEX)
MENU_BUTTON_BG_HEX = "#3D484C"
MENU_BUTTON_FG_HEX = "#0078A8"
MENU_BUTTON_FG_HOVERED_H... | true |
b185564f415a1076a7d6e87a82f069a53dc4737b | Ruby | antoniojking/backend_mod_1_prework | /section1/ex6.rb | UTF-8 | 1,207 | 4.46875 | 4 | [] | no_license | # variable name equals integer
types_of_people = 10
# variable name equals string with embedded variable (interpolation)
x = "There are #{types_of_people} types of people."
# variable name equals string
binary = "binary"
# variable name equals string
do_not = "don't"
# variable name equals string with emdedded variable... | true |
b8ec06d9df27bad2e37ce44b5b89b88db1f6ae76 | Ruby | cebucodecamp/ccc_demos_ruby | /lib/refactorings/decompose_conditional.rb | UTF-8 | 964 | 3.015625 | 3 | [] | no_license | require 'time'
module Refactorings::DecomposeConditional
# start of april
SUMMER_START = Time.parse('2016-04-01').to_date
# end of june
SUMMER_END = Time.parse('2016-07-01').to_date
WINTER_RATE = 9.99
WINTER_SERVICE_CHARGE = 2.50
SUMMER_RATE = 6.99
module Original
class CalculateCharge
def ... | true |
3942a110791d3a288e4af7991409478dc2ba196c | Ruby | carolinecollaco/RubyCodeAcademy | /OrdenandoOHash.rb | UTF-8 | 236 | 3.296875 | 3 | [] | no_license | puts "Entre com o texto: "
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each {|word| frequencies [word] += 1}
frequencies = frequencies.sort_by do |frequencie, count|
count
end
frequencies.reverse!
| true |
e377509727eeed9f7a4d28a08a3b4149ebeb0bd3 | Ruby | zhangjx/apimaster | /lib/apimaster/error.rb | UTF-8 | 2,289 | 2.671875 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
#
# Copyright (C) 2011-2012 AdMaster, Inc.
#
# @author: sunxiqiu@admaster.com.cn
module Apimaster
class NormalError < StandardError
attr_reader :code
attr_reader :error
attr_reader :resource
attr_reader :field
# error :missing, :missing_field, :invalid, :already_exists
de... | true |
4118ce6e721f79cba7b55e729a62a20600110574 | Ruby | Bates550/vidigem | /vidigemTest.rb | UTF-8 | 3,125 | 3.5 | 4 | [] | no_license | =begin
Mystery:
AfterEarth
Prometheus
Inception
Love:
Inception
MissingPieces
Casablanca
Betrayal:
Casablanca
Gladiator
TheDarkKnightRises
=end
class
inception = [ "love", "mystery" ]
afterEarth = ["mystery"]
prometheus = ["mystery"]
casablanca = ["love", "betrayal"]
missingPieces = ["love"]
gladiator = ["b... | true |
9b3b7280743db9a6450f0fb7761b948dc2194065 | Ruby | implicitly-awesome/trial | /lib/router.rb | UTF-8 | 636 | 3.03125 | 3 | [] | no_license | require 'singleton'
##
# Routes registry
class Router
include Singleton
attr_reader :routes
def initialize
@routes = {}
end
##
# Creates and adds route to the registry
# @param [String] URL path
# @param [String] HTTP request method
# @param [Proc] an action
def add(path, method, &action)
... | true |
cffac4a9c628569100e8d9a0d388b9cfa69069c6 | Ruby | baughje/practice | /stats_class/run.rb | UTF-8 | 260 | 2.90625 | 3 | [] | no_license | require "stats"
class StatRunner
def poll
loop do
data_array = []
File.new("samples.txt", "r").each { |line| data_array << line.chomp }
end
end
def results
@stats.sample_size
puts "The result is #{ result }"
end
end
| true |
f9f6c874f7bac977a504fca707484fd8229c5f0f | Ruby | kojix2/ProbabilityCalculator | /cardanddiagnosis.rb | UTF-8 | 1,971 | 2.875 | 3 | [] | no_license | # 2013-2018 kojix2
# カードと鑑別疾患
class CardAndDiagnosis
def initialize(dir)
@reader = nil
temp_path = "#{dir}/diagnosis/diagnosis.csv"
puts temp_path
begin
*@reader = CSV.read(temp_path)
rescue StandardError
@reader = []
end
window = TkToplevel.new(title: '鑑別疾患カード')
# 左側のフレ... | true |
97559ce8ba381fa7ebafc1ee90a44498bffcc19f | Ruby | rhomobile/rhodes | /spec/framework_spec/app/spec/core/proc/arity_spec.rb | UTF-8 | 2,879 | 2.671875 | 3 | [
"MIT"
] | permissive | require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Proc#arity" do
before :each do
@p = ProcSpecs::Arity.new
end
ruby_version_is ""..."1.9" do
it "returns -1 for a block taking no arguments" do
@p.arity_check { 1 }.should ==... | true |
3bfa66038df527f6b5e37999fd9e71ad2af4c960 | Ruby | mqprogramming/classes-homework | /specs/family_class_specs.rb | UTF-8 | 1,439 | 3.03125 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/reporters')
require_relative('../family_class')
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
class TestFamily < MiniTest::Test
def setup()
members = [
{
name: "Matthew",
age: 22
},
{
name: "Jonathan",
... | true |
296f033603ab3fec18ad6bc86011d787e11613e1 | Ruby | germanlinux/Lemon-labs | /Ruby/cobol2java/explore_script.rb | UTF-8 | 1,629 | 2.609375 | 3 | [] | no_license | file = ARGV.shift
content = File.readlines(file)
h_nom={}
content.each do |ligne|
ligne.chomp!
tab = ligne.split('/')
nom_script = tab[-1]
h_nom[nom_script] = 1
pgm = tab[-3]
script = File.readlines(ligne)
taille = script.size
h_nom[nom_script] = taille
libelle ="TODO"
script1 =""
if taill... | true |
fdab2df2ca1f6369e25b0826ee5e96c655a2671c | Ruby | NicciTheNomad/Ruby-Coding-Dojo-Class | /RubyAssignments/Ruby_TDD/project/project.rb | UTF-8 | 582 | 3.3125 | 3 | [] | no_license | class Project
attr_accessor :name, :description, :team_member
def initialize name, description, team_member
@name = name
@description = description
@team_member = team_member
end
def elevator_pitch
"#{@name}, #{@description}"
end
def add_to_team
"team member: #{team_member}"
... | true |
f731872deff91b7d89354f076fd665937fc2cf53 | Ruby | WestDragonIroh/HANGMAN | /main.rb | UTF-8 | 529 | 3.71875 | 4 | [] | no_license | require_relative 'game'
require_relative 'display'
puts ' '
puts "\e[1;32mWelcome to console edition of Hangman !!! \e[0m"
puts ' '
def play
game = Game.new
game.start
play_again
end
def play_again
puts ''
puts "\e[1;32mWould you like to play again? Type \"Y\" or \"N\". \e[0m"
respond = get... | true |
3d7ca2ac591e34c32c9dfd942c4802c39385e3f7 | Ruby | lolptdr/cars | /carcolor.rb | UTF-8 | 414 | 3.953125 | 4 | [] | no_license | class Car
@@repaint_count = 0
def initialize(my_color)
@my_color = my_color
end
def color
@my_color
end
def repaint_count
@@repaint_count
end
def paint(my_color)
@@repaint_count += 1
@my_color = my_color
end
end
c = Car.new("blue")
puts c.color # blue
puts c.repai... | true |
79c48416f3cb7a39ee7d1e7dbf50b95f9d561520 | Ruby | albertbahia/wdi_june_2014 | /w02/d02/francis_castillo/pets/lib/dog.rb | UTF-8 | 336 | 3.328125 | 3 | [] | no_license | class Dog < Pet
attr_reader(:ear_type)
def initialize(name, owner, age, ear_type)
# @name = name
# @owner = owner
# @age = age
# @food_eaten = []
super(name, age, owner)
@ear_type = ear_type
end
def eat(food)
super(food)
puts("woof")
end
def bark ()
return "woof wo... | true |
e282f4d99ae4b45a77189f7b8097b4105a95f7c2 | Ruby | gillysayres/Meetadoc | /spec/models/patient_spec.rb | UTF-8 | 1,117 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Patient, type: :model do
it 'creates a patient' do
patient = Patient.new(
name: 'John Doe',
cpf: '532.345.501-52',
birth_date: 1988-05-20
)
expect(patient.name).to eql "John Doe"
expect(patient.cpf).to eql "532.345.501-52"
expect(patient.b... | true |
90db8594390952cf11b3611c8c1393286babbbb6 | Ruby | masc-ucsc/udsim | /lib/Org.rb | UTF-8 | 494 | 3.234375 | 3 | [
"MIT"
] | permissive |
module DesignSim
# Company organization class.
class Org
def initialize()
end
# Parse the org.xml file to find the people available on the pool for hiring
def parse!(xml)
end
# Look for a person with the best match to the following skills. All the
# skills have the same importance
... | true |
bc6efa9871419cd20401c927edc10811de79576f | Ruby | KentaroKageyama/furima-35204 | /spec/models/user_spec.rb | UTF-8 | 6,220 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー新規登録' do
context 'ユーザー新規登録できる時' do
it 'nickname, email、password, password_confirmation, first_name, last_name, first_name_kana, last_name_kana, birthdayが存在すれば登録できる' do
exp... | true |
76e8468306c06dfc0cb7f087bd5c8ebfdafda3c2 | Ruby | Zszywka/my_first_programms | /w2/initials.rb | UTF-8 | 809 | 3.671875 | 4 | [] | no_license | # Napisz metodę initials , która wypisuje inicjały osoby na podstawie jej pełnego imienia
# Wszystkie znaki inicjałów powinny być pisane z dużej litery.
# initials('Jan Kozlowski') => 'JK'
# metoda do bezposredniego wpsiania:
a = "tomasz kot"
array = a.scan(/\w+/)
name = [] << array[0]
surname = [] << array[1]
puts n... | true |
c0dc841f297acbb1a85366afa2d4722b7c51adb0 | Ruby | czcraig/pub_lab | /specs/pub_spec.rb | UTF-8 | 614 | 2.953125 | 3 | [] | no_license | require("minitest/autorun")
require_relative("../pub.rb")
require_relative("../drinks.rb")
class PubTest < MiniTest::Test
def setup
@drink1 = Drink.new("Tennants", 4.50)
@drink2 = Drink.new("Strongbow", 4.25)
@drink3 = Drink.new("Buckfast", 6.50)
@pub = Pub.new("The Standing Order", 500, [@drink1, ... | true |
99739a4402db36f415f334f60b696660c41f1645 | Ruby | bureaucratix/count-elements-seattle-web-career-042219 | /count_elements.rb | UTF-8 | 210 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def count_elements(array)
counted_elements = {}
array.each do |element|
counted_elements[element] = 0 if counted_elements[element].nil?
counted_elements[element] += 1
end
counted_elements
end
| true |
22cd0bf653591f4b557f6f4701e04c0a995fe468 | Ruby | ha4gu/atcoder | /Other/2019/AISING/B.rb | UTF-8 | 164 | 3.203125 | 3 | [] | no_license | _n = gets
a, b = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i)
puts [ps.count { |p| p <= a }, ps.count { |p| p.between?(a+1, b) }, ps.count { |p| p > b }].min
| true |
072ba1f5a0c5ba9474d2163c257da81599ad2cd6 | Ruby | codykrieger/cube-ruby | /lib/cube.rb | UTF-8 | 3,073 | 3.078125 | 3 | [
"MIT",
"Ruby",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'cube/version'
module Cube
require 'date'
# We'll be sending data to Cube over a UDP socket.
require 'socket'
# Cube requires data to be in JSON format.
require 'json'
class Client
# A namespace to prepend to all Cube calls.
attr_accessor :namespace
# We'll use this to eliminate any u... | true |
19be8226ec7a9c0cc02e7fbf3293becc16f70480 | Ruby | Fishbone12/zadachi | /8.rb | UTF-8 | 486 | 2.96875 | 3 | [] | no_license | r1=Rational(1,2)
r2=Rational(1,3)
r3=Rational(1,8)
ro=Rational(1,r1+r2+r3)
puts ro.to_f
=begin Задача 8.
Три сопротивления R1, R2, R3 соединены параллельно. Найти
сопротивление соединения R0 по формуле:
1/R0 = 1/R1+ 1/R2+ 1/R3
Исходные данные взять из контрольного примера.
Контрольный пример: R1=2, R2=4, R3=8. Результа... | true |
3c8b0953aaf300245bfe2d7d06c2c565ff2656bd | Ruby | ellerynz/toy_robot_simulator | /lib/commands/null_command.rb | UTF-8 | 174 | 2.6875 | 3 | [] | no_license | class NullCommand < Command
def initialize(instruction)
@instruction = instruction
end
def execute
print "Unknown instruction '#{@instruction}'\n"
end
end
| true |
9d82cf6a6899c7d0fd24b331fe3557e559655d5e | Ruby | cheezenaan/procon | /atcoder/abc109/c.rb | UTF-8 | 146 | 2.75 | 3 | [] | no_license | # frozen_string_literal: true
n, x = gets.split.map(&:to_i)
xs = gets.split.map { |xi| (xi.to_i - x).abs }
puts xs.inject { |r, xi| r.gcd(xi) }
| true |
86f4170ba672dd2df4d6edbf35d66689d47b4caa | Ruby | Chanson9892/ruby-enumerables-reverse-each-word-lab-sea01-seng-ft-082420 | /reverse_each_word.rb | UTF-8 | 331 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(sentence)
string = sentence.split(" ")
new_sentence = []
new_sentence2 = []
string.each do |word|
new_sentence << word.reverse
end
result = new_sentence.join(" ")
result
string.collect do |word|
new_sentence2 << word.reverse
end
result2 = new_sentence2.join(" ")
r... | true |
a889ee42435ed76f80c254c3106e7a47a9efc423 | Ruby | mitchellheiser/CA-challenges | /projects/mvc/view.rb | UTF-8 | 888 | 3.96875 | 4 | [] | no_license |
class StatsView
def greeting
puts "welcome to my awesome stats app"
end
def menu
puts "1. Insert numbers"
puts "2. List numbers"
puts "3. Show average"
puts "4. Quit"
gets.chomp.to_i
end
# def read_numbers
# values= []
# puts "please enter one number per line (-1 to end):"... | true |
6e0195ae3c99fef8c23d338fb6edc54da0a4fbb7 | Ruby | DeedaG/my-each-v-000 | /my_each.rb | UTF-8 | 201 | 3.1875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def my_each(words)
if block_given?
index = 0
while index < words.length
yield(words[index]) #
index = index + 1
end
words
else
prints "This block should not run!"
end
end
| true |
46f5ca401b7f370e734640d7201f9a27dedd8e85 | Ruby | Cireou/ruby-oo-practice-relationships-domains-yale-web-yss-052520 | /app/models/Easy/Bakery/ingredients.rb | UTF-8 | 398 | 3.203125 | 3 | [] | no_license | class Ingredient
attr_accessor :dessert, :name, :calorie
@@all = []
def initialize(args)
args.each{|key, val| self.send(("#{key}="), val)}
@@all << self
end
def bakery()
@dessert.bakery()
end
def self.find_all_by_name(name)
all().select{|ingredient| ingredi... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.