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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ff06773650124ad068b851616fac8c8a2cf9580a | Ruby | caltonhill/dice_game | /code/print_dice.rb | UTF-8 | 732 | 3.390625 | 3 | [] | no_license | def print_dice(num)
resources_path = '../resources/'
case num
when 6
file_content = File.read(resources_path + '6.txt')
print "#{file_content}"
when 5
file_content = File.read(resources_path + '5.txt')
print "#{file_content}"
when 4
file_content = File.read(resources_path... | true |
2f1fa698d480a537241c088815d210e80f7e9600 | Ruby | upper-hand/availability | /examples/scheduler.rb | UTF-8 | 3,291 | 3.40625 | 3 | [
"Unlicense",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative '../lib/availability'
#
# This is just an example of a scheduler that might be used with availabilities. It's a work in
# progress that's helping to flesh out the design of availabilities.
#
class Scheduler
attr_reader :availabilities, :scheduled
#
# availabilities: a list of Availability::Abst... | true |
c6a27050e46922f919292dd80f1a7d904c845577 | Ruby | JayTeeSF/fortune_teller | /lib/fortune_teller/chooser.rb | UTF-8 | 2,318 | 2.90625 | 3 | [
"MIT"
] | permissive | require_relative "list_renderer"
require_relative "logger"
module FortuneTeller
class Chooser
LOCATIONS = [ :tl, :tr, :bl, :br ]
def self.subset(list, num=list.size)
Logger.log("got list: #{list.inspect}, num: #{num.inspect}")
choices = list.dup
num.times.collect {|num|
reduce_choic... | true |
9942c17abd23432e89e669f866b90c31e1377bc1 | Ruby | banerjed/MyOnlinePractice | /test/unit/doctor_test.rb | UTF-8 | 2,270 | 2.5625 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../test_helper'
class DoctorTest < Test::Unit::TestCase
fixtures :doctors,:testimonials,:locations,:users,:practices
def setup
@doc = Doctor.find(1)
@mydoctor_tst = doctors(:doctor_00001)
end
# Replace this with your real tests.
def test_truth
as... | true |
3c4bf3113d933be71f3df48141d0fd0db6113807 | Ruby | chrissiedunham/cycle_tracker | /app/models/cycle.rb | UTF-8 | 1,057 | 2.65625 | 3 | [] | no_license | class Cycle < ActiveRecord::Base
has_many :days, -> { order(number: :asc) }
belongs_to :user
def to_csv
attributes = [
:bleeding,
:sensation,
:characteristics,
:cervix,
:temp,
:created_at,
:updated_at,
:date,
:number,
:cycle_id,
:weight,
... | true |
3f3784a2e2aefbb4f7ba4525f6df552f6e591056 | Ruby | RaulZhao/learning | /questions/leetcode_ruby/Remove_Duplicates_from_Sorted_Array.rb | UTF-8 | 1,566 | 4.15625 | 4 | [] | no_license | # Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.
# Since it is impossible to change the length of the array in some languages, you must instead have the result be pla... | true |
27af3130af2e587ee1a9ca31bf4286e65e9102c3 | Ruby | rutvij-pandya/twitter_app | /lib/twitter_lib/feed.rb | UTF-8 | 2,990 | 2.75 | 3 | [] | no_license | module TwitterLib
class Feed < Base
DEFAULT_NO_OF_POST_LIMIT = 100
BATCH_SIZE = 100
def initialize
super()
end
def export_posts_by_hashtag(hashtag, no_of_posts=DEFAULT_NO_OF_POST_LIMIT)
begin
return {success: false, error: "Invalid format of hastag. Sample - \'#ruby\'"} unle... | true |
951cdfe16212f9e965d8751d0cacf4fafbc3601b | Ruby | kchasel/stub.born | /lib/stub_born.rb | UTF-8 | 1,408 | 2.59375 | 3 | [] | no_license | module RSpec
module Mocks
module Methods
def stub_return_of(message)
ReturnStub.new(self, message)
end
end
end
end
class ReturnStub
def initialize(receiver, message)
@receiver = receiver
@message_sym = message.to_sym
meth = @receiver.method(@message_sym)
if @receive... | true |
04a761a7232953b3ddbd87b61ddfdbbf300ad265 | Ruby | molit-korea/main | /Pages/2017 국토교통 빅데이터 해커톤 참가작/molit_HAB-master/elastic/logstash-5.5.2/vendor/bundle/jruby/1.9/gems/sequel-4.49.0/lib/sequel/plugins/timestamps.rb | UTF-8 | 4,776 | 2.59375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | # frozen-string-literal: true
module Sequel
module Plugins
# The timestamps plugin creates hooks that automatically set create and
# update timestamp fields. Both field names used are configurable, and you
# can also set whether to overwrite existing create timestamps (false
# by default), or wheth... | true |
dc7c32a8534c129a997f1f40b1bd7e37aeba5ab4 | Ruby | MaximL1/Ruby_test | /Accaunts_class/accountClass.rb | UTF-8 | 813 | 2.90625 | 3 | [] | no_license | require 'rubygems'
require 'watir'
require 'json'
class Accounts
def initialize(b)
@b = b
end
def getAccount
divs = @b.divs(class: "main-info")
data = {
Account: []
}
divs.each do |div|
str = div.html
name = str[(str.index('class="n... | true |
0c8e6ffb7c9412f77347e0c7f22ee3b84c896eab | Ruby | case-iot/app_model | /lib/ontology/local_vocabulary.rb | UTF-8 | 452 | 2.65625 | 3 | [] | no_license | require 'rdf'
module Model
class LocalVocabulary
def self.method_missing(name, *arguments, &block)
uri_for(name)
end
def self.name
uri_for('name')
end
def self.question_type
uri_for('question')
end
def self.answer_type
uri_for('answer')
end
def self.uri... | true |
ac9ca1cfac2ed0f997718b380e77fc3d45fb44a6 | Ruby | liefni/ruby_atbash | /atbash.rb | UTF-8 | 321 | 2.953125 | 3 | [] | no_license | require './atbash_cypher.rb'
ORIGINAL_CHARS = 'abcdefghijklmnopqrstuvwxyz'
REPLACEMENT_CHARS = 'oephjizkxdawubnytvfglqsrcm'
ENCRYPTED_TEXT = 'knlfgnb, sj koqj o yvnewju'
cypher = AtbashCypher.new()
cypher.original_chars = ORIGINAL_CHARS
cypher.replacement_chars = REPLACEMENT_CHARS
puts cypher.decrypt(ENCRYPTED_TEXT... | true |
4d168e85c089aa2c93388b72d887a06a01e303a6 | Ruby | gsisson/ruby_lib | /rename.add.suffix | UTF-8 | 838 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby
# require_relative 'lib/dir2'
require_relative 'lib/string_colorize'
def usage()
STDERR.puts "usage: #{File.basename(__FILE__)} SUFFIX <files>"
STDERR.puts " ex: #{File.basename(__FILE__)} \".avi\" *.mpg"
abort
end
def main
usage if ARGV.count < 2
suffix = ARGV[0]
ARGV.shift
AR... | true |
1362e02d8953bc532cadd1a16355ffee882ae85f | Ruby | lukew244/boris-bikes | /spec/docking_station_spec.rb | UTF-8 | 1,038 | 2.6875 | 3 | [] | no_license | require 'docking_station.rb'
describe DockingStation do
let(:bike) { double :bike }
it { is_expected.to respond_to :release_bike }
it { is_expected.to respond_to :dock }
it { is_expected.to respond_to :bikes }
it { is_expected.to respond_to :capacity }
it 'raises an error' do
expect { subject.releas... | true |
c52ceaf5c5446a2e81f191136abf2b018d95e7ee | Ruby | davidyoung604/ProjectFIREBALL | /test/benchmarking/category_extensions_order_name.rb | UTF-8 | 407 | 2.5625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | ActiveRecord::Base.logger.level = 1
# Pre-benchmark fiddling showed a marginal improvement.
puts '--- Sorting category extensions by name ---'
Benchmark.ips do |bm|
bm.report('original: ') do
cat = Category.find(4)
cat.extensions.sort_by(&:name).each { |e| e }
end
bm.report('updated: ') do
cat = Ca... | true |
39c14f2e20ab73f96d5260ef33bc8517a6d2f639 | Ruby | gpcucb/ray-tracing-sergioKmoralesV | /tests/vector_test.rb | UTF-8 | 2,283 | 3.421875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/reporters'
require './vector'
class VectorTest < Minitest::Test
def setup
@a_vector = Vector.new(4,5,8)
@another_vector = Vector.new(5,6,7)
end
def test_01_creates_an_object_vector_and_saves_values_as_floats
@a_vector = Vector.new(4,5,8)
assert_equal(... | true |
6cc77d147bb48119fa7e925d44e165471f42c5d3 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/combine_anagrams_latest/1711.rb | UTF-8 | 164 | 2.96875 | 3 | [] | no_license | #!/usr/bin/env ruby
#
# HW 1: Ruby calisthenics
#
# Part 3: anagrams
#
def combine_anagrams(words)
words.group_by { |word| word.downcase.chars.sort }.values
end
| true |
6e0ae41c20b0f5b9d8ac5e71e2ab65a940bdba9f | Ruby | chetna1726/vinsol_campus_hiring | /app/models/mcq.rb | UTF-8 | 414 | 2.78125 | 3 | [] | no_license | class MCQ < Question
validate :ensure_only_one_answer
validate :ensure_atleast_two_options
def ensure_only_one_answer
answers_count = options.select(&:answer?).length
if answers_count != 1
errors.add(:answers, "Select one option as correct answer")
end
end
def ensure_atleast_two_options
... | true |
999b16366be3c6d715ca8ab5b6c48992eeb92ea2 | Ruby | aaaasmile/cup-sinatra | /middlewares/cup_srv/database/captcha_validator.rb | UTF-8 | 1,601 | 2.59375 | 3 | [] | no_license | #file: captcha_validator.rb
$:.unshift File.dirname(__FILE__)
require 'rubygems'
require 'log4r'
require 'net/http'
require 'openssl'
include Log4r
module MyGameServer
class CaptchaValidator
attr_reader :success, :last_error
def initialize(secret)
#verify captacha with an api call https://www.google... | true |
953bd5abd570f49af47283ca3348e4d642bd151f | Ruby | qbart/handy_toolbox | /lib/handy_toolbox/tool_menu_item.rb | UTF-8 | 374 | 2.640625 | 3 | [
"MIT"
] | permissive | module HandyToolbox
class ToolMenuItem
ICON = ' '.freeze
attr_reader :id, :parent, :tool
def initialize(parent, tool)
@id = Ids.next
@parent = parent
@tool = tool
end
def to_s
if @tool.desc.nil?
@tool.name
else
[@tool.name, @tool.desc]
end... | true |
638f444162ff798a25fe9596bf93de4e28adbfec | Ruby | mufid/rack-talk | /3-order/config.ru | UTF-8 | 498 | 3.03125 | 3 | [] | no_license | require 'pry'
class EaterBase
def initialize(app)
puts "Initialized with app name: #{app.name}"
@app = app
end
end
class Eater1 < EaterBase
def call(env)
puts 'CUMI DIGORENGGG'
@app.call(env)
end
def name; 'Eater1'; end
end
class Eater2 < EaterBase
def call(env)
@app.call(env)
end
... | true |
8bec074fafb32005ecd485f19baa57715ab0764a | Ruby | burkhart-andrew/Launch_School | /101/lesson_3/exercise_3.rb | UTF-8 | 959 | 4.03125 | 4 | [] | no_license | 3.1
Show an easier way to write this array:
flintstones = ["Fred", "Barney", "Wilma", "Betty", "BamBam", "Pebbles"]
flintstones = %w(Fred Barney Wilma Betty BamBam Pebbles)
3.2
How can we add the family pet "Dino" to our usual array:
flintstones.push("Dino")
flintstones << "Dino"
3.3
How can we add multiple items... | true |
f02bff81e5703023f72fe2bd5a608c27cda74cde | Ruby | hlopezm/rails-week-2 | /app/models/event.rb | UTF-8 | 1,142 | 2.671875 | 3 | [] | no_license | class Event < ActiveRecord::Base
#
belongs_to :user
validates :name, presence: true, length: { maximum: 60 }
validates :description, length: { minimum: 100}, allow_blank: true
validate :start_at_blank, :end_at_blank, :end_at_cannot_start_before_start_at
validates :user, presence: true
#scope :already_sta... | true |
03def7d0a6cf51566bf32ce426239dbb5e263816 | Ruby | Sivard/flashcards | /app/services/words_parser.rb | UTF-8 | 946 | 2.796875 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
class WordsParser
def initialize(*params)
@user_id = params[0]
@original_css = params[1]
@translated_css = params[2]
@url = params[3]
@block_id = params[4]
Log.create(user_id: @user_id, status: 0, msg: 'Начало загрузки')
end
def run
doc = Nokogi... | true |
fabb3bf94956c82d7aa1728ad4b74c4116d4a5eb | Ruby | nicolaracco/simple_etl | /lib/simple_etl/source/parse_result.rb | UTF-8 | 707 | 2.640625 | 3 | [] | no_license | require 'ostruct'
module SimpleEtl
module Source
class ParseResult
attr_reader :rows
def initialize
@rows = []
end
def valid?
# return false if at least one row is not valid
!@rows.detect { |r| !r.valid? }
end
def errors
@rows.inject([]) { |m... | true |
b7a0f1b65f3b28c00adc08ad0b3c2b8bce1185c9 | Ruby | thuga-muffin/Development | /ruby/ruby the hard way/ex36.rb | UTF-8 | 2,738 | 3.859375 | 4 | [] | no_license |
# the beginning
def beginning
puts "You have the choice between right and left."
print "Response: "
choice = $stdin.gets.chomp
choice.downcase!
if choice == "left"
the_left
elsif choice == "right"
the_right
else
puts "Only right or left"
end
end # beginning
# choosing left
def the_left
puts "You ... | true |
4713495ba96911f7ac9eadd20014d6dc843e3cfa | Ruby | Jhua96/Launchschool_exercises | /RB101_small_problems_exercises/easy_5/ASCII.rb | UTF-8 | 192 | 3.09375 | 3 | [] | no_license | def ascii_value(str)
str.chars.inject(0) {|sum, n| sum + n.ord}
end
p ascii_value('Four score') == 984
p ascii_value('Launch School') == 1251
p ascii_value('a') == 97
p ascii_value('') == 0 | true |
72f82844d48f74fcb840d86d1e3d76599a6ca9d8 | Ruby | JeanPierreGrau/promo-2-challenges | /02-OOP/08-Cookbook/lib/cookbook.rb | UTF-8 | 963 | 3.703125 | 4 | [] | no_license | require 'csv'
class Cookbook
attr_accessor :file, :recipe
def initialize(file)
# TODO: Retrieve the data from your CSV file and store it in an instance variable
@file = file
@recipes = csv_to_array(@file)
end
# TODO: Implement the methods to retrieve all recipes, create, or destroy recipes
#... | true |
58ed1dce9c62739303ccee6c4c158877ca509e23 | Ruby | stereocat/cisco_acl_intp | /lib/cisco_acl_intp/scanner.rb | UTF-8 | 4,642 | 2.59375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'strscan'
require 'cisco_acl_intp/scanner_special_token_handler'
module CiscoAclIntp
# Lexical analyzer (Scanner)
class Scanner
# include special tokens data and its handlers
include SpecialTokenHandler
# Constructor
# @return [Scanner]
def initialize
... | true |
2e18161d5ad22475d5fb8c2f5472a02f7b930351 | Ruby | zlindacz/codeeval | /easy/road_trip.rb | UTF-8 | 2,262 | 3.609375 | 4 | [] | no_license | =begin
ROAD TRIP
CHALLENGE DESCRIPTION:
You've decided to make a road trip across the country in a straight line. You have chosen the direction you'd like to travel and made a list of cities in that direction that have gas stations to stop at and fill up your tank. To make sure that this route is viable, you need to k... | true |
2badc1e80594e3023c7bda95dbba30a54f6c4763 | Ruby | BWITS/card_game | /spec/unit/card_game/core_ext_spec.rb | UTF-8 | 1,916 | 2.640625 | 3 | [] | no_license | require 'spec_helper'
require 'card_game/core_ext'
describe CardGame::CoreExt, aggregate_failures: true do
describe 'String' do
it 'points to the right things' do
expected = CardGame::Card.from_string("AH")
assert_equal expected, "A".hearts
assert_equal expected, "A".♡
assert_equal expec... | true |
12bbed19c701ae1dcddb6f8f50f8f15030d3ce10 | Ruby | bodyshopbidsdotcom/shift_planning | /lib/shift_planning/client.rb | UTF-8 | 1,714 | 2.6875 | 3 | [
"MIT"
] | permissive | require "http"
require "json"
require "base64"
module ShiftPlanning
class Client
attr_accessor :strict
def initialize(config = {})
raise ArgumentError.new('Missing username') unless config.key?(:username)
@username = config[:username]
raise ArgumentError.new('Missing password') unless con... | true |
2a21fb9812497a7fa1cd21cf279e243b416a3f58 | Ruby | BookingBug/bookingbug_yellowfin | /app/models/bookingbug_yellowfin/person_capacity_usage.rb | UTF-8 | 3,515 | 2.578125 | 3 | [
"MIT"
] | permissive | module BookingbugYellowfin
class PersonCapacityUsage < ActiveRecord::Base
attr_accessible :person_id, :date, :total_time_hrs, :time_booked_hrs, :time_blocked_hrs, :yf_format_date
def self.populate_all_capacity_usage
failed_imports = []
p 'populate all historic capacity usage'
$stdout.sync ... | true |
4371bb58a364d866016f2492b38fe1697cc1d9dd | Ruby | chrisaugust/Launch-School-Intro-to-Programming | /basics/exercise_three.rb | UTF-8 | 426 | 4.1875 | 4 | [] | no_license | # exercise 3: movie hash
movies = {}
still_inputting_movies = "yes"
while still_inputting_movies == "yes"
puts "Name of movie: "
movie = gets.chomp.to_s
puts "Year?"
year = gets.chomp.to_i
movies[movie] = year
puts "Do you want to input another movie? (yes or no)"
answer = gets.chomp
if answer ... | true |
94c063c1cc81204a41a565fce0c333ec9de4407a | Ruby | jsonperl/boondoggle | /multicore_random.rb | UTF-8 | 1,225 | 3.25 | 3 | [] | no_license | require "etc"
class MulticoreRandom
def initialize
@dataset = File.readlines("data").map(&:to_i).freeze
@pids = []
@readers = []
end
# Brute force recursive
def compute(goal, dataset)
element = dataset.delete_at(rand(dataset.length))
if element < goal
compute(goal - element, datase... | true |
1c0b260f2eca7f8d0c5c4e0775a074b4c0c04ec2 | Ruby | lishulongVI/leetcode | /ruby/58.Length of Last Word(最后一个单词的长度).rb | UTF-8 | 1,366 | 3.90625 | 4 | [
"MIT"
] | permissive | =begin
<p>Given a string <i>s</i> consists of upper/lower-case alphabets and empty space characters <code>' '</code>, return the length of last word in the string.</p>
<p>If the last word does not exist, return 0.</p>
<p><b>Note:</b> A word is defined as a character sequence consists of non-space characters only.</p>... | true |
c35e87b4eea2a94012eaaf20e464cd5966e97aca | Ruby | emjose/ruby-oo-inheritance-modules-nyc04-seng-ft-071220 | /lib/dancer.rb | UTF-8 | 502 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative './class_methods_module.rb'
require_relative './dance_module.rb'
require_relative './fancy_dance.rb'
class Dancer
extend FancyDance::ClassMethods
include FancyDance::InstanceMethods
# This is a module in dance_module.rb. include keyword allows us to use all of the methods of
# th... | true |
b35eccc385323371d99bf37fed5dfb22881630bb | Ruby | sad16/thinknetica-rails-advanced-qna | /app/services/search/base.rb | UTF-8 | 886 | 2.609375 | 3 | [] | no_license | module Services
module Search
class Base < ApplicationService
class Error < StandardError; end
class EmptySearchError < Error; end
def call(params)
search(params.to_h.deep_symbolize_keys)
end
private
def search(params)
search_options = search_options(params)
... | true |
40896f4289c649d279f0c8266d037c2f8fb4f4c6 | Ruby | GaryZCLau/programming-univbasics-4-square-array-nyc04-seng-ft-030920 | /lib/square_array.rb | UTF-8 | 218 | 3.484375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
# your code here
squared_array = []
counter = 0
while counter < array.length do
squared = array[counter] ** 2
squared_array << squared
counter += 1
end
squared_array
end
| true |
5e294fe73abeadab35bbe4518c7c1f873b886db4 | Ruby | I-Mircheva/rsa-tp-hw | /spec/models/rsa_spec.rb | UTF-8 | 1,020 | 2.828125 | 3 | [] | no_license |
require 'rails_helper'
require 'spec_helper'
RSpec.describe RSA do
let(:msg) { "The quick brown fox jumped over the lazy dog!" }
let(:rsa) { RSA.new(217, 59, 119) }
let(:new_keys) { rsa.new_key }
let(:rsa_rand) { RSA.new(new_keys[0], new_keys[1], new_keys[2]) }
it "Tries if return n works" do
expect(r... | true |
a025d41a63c040eff723920e347b5c01178e35b9 | Ruby | suguru03/leetcode | /algorithms/0172.Factorial Trailing Zeroes/solution.rb | UTF-8 | 154 | 3.390625 | 3 | [] | no_license | # @param {Integer} n
# @return {Integer}
def trailing_zeroes(n)
result = 0
while n > 0 do
n = n / 5 | 0
result += n
end
return result
end
| true |
3b1c9f28957ca930426e92a0e82fbd9f75434f2a | Ruby | anilsingh826/examplecrm | /app/models/dynamic_field.rb | UTF-8 | 757 | 2.515625 | 3 | [] | no_license | class DynamicField < ActiveRecord::Base
attr_accessible :roles, :model_name, :name, :type
ROLES = %w[admin client tech]
DATA_TYPES = [
["Text","string_type"],
["Paragraph text","text_type"],
["Radio buttons", "radio_type"],
["Checkboxes", "check_boxes_type"],
["Integer", "integer_... | true |
272ce97bfbfe6f3afcf79f9b9d6d2f9c73089e27 | Ruby | puttyplayer/fraction_calculator | /fraction.rb | UTF-8 | 2,982 | 4.34375 | 4 | [] | no_license | #this is a fractions program that will add subtract multiply and reduce
#it might also convert fraction into decimal
require 'rational'
#above require allows you acsess to two methods
#the methods are lcm and gcd
#use like this 12.gcd(4) or 12.lcm(3)
#lcm is the number for common denominator
#methods definition sectio... | true |
0c966392a9ec6cd9e7b028a3755328fadb4d93a0 | Ruby | ox/Angstrom | /bin/angstrom | UTF-8 | 3,346 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'fileutils'
include FileUtils
# this is a cli tool to make getting running with angstrom easier.
def inform
puts """
Angstrom is an asynchronous ruby web framework that's fronted by mongrel2
and makes use of Actors in order to handle requests. It is preferred to use
rubinius2... | true |
9cb7bb037034b15cbb47e7cb66ef49637f777967 | Ruby | agussuparman/belajar-dasar-ruby | /9-hash/2-hash_default_value.rb | UTF-8 | 306 | 3.125 | 3 | [] | no_license | hash = {nama: "Agus Suparman", "alamat" => "Gunungkidul"}
puts hash
puts hash.fetch(:nama, "Suparman Agus")
puts hash[:salary] # nil
puts hash.fetch(:salary, 50_000_000)
puts "\n"
# Cara lain membuat hash dan mendefinisikan nilai default hash
hash = Hash.new("belum ada nilai")
puts hash[:nilai]
puts hash[:nilai_dua] | true |
c6ffe0b603e5a241ac05edcd9df68689893af671 | Ruby | OlegLazaryev/rubywarrior | /player.rb | UTF-8 | 1,294 | 3.296875 | 3 | [] | no_license | require 'environment'
require 'condition'
class Player
def initialize
@condition = Condition.new
@environment = nil
end
def play_turn(warrior)
before_turn(warrior)
process(warrior)
after_turn
end
private
def before_turn(warrior)
@environment = Environment.new(warrior)
condition.cu... | true |
2ed6a6114936aeb02cd8ab36c611306abb632bb5 | Ruby | ljorgens/triangles | /spec/triangle_spec.rb | UTF-8 | 1,092 | 3.234375 | 3 | [] | no_license | require("rspec")
require("triangle")
require("pry")
describe(Triangle) do
describe("#is_triangle?") do
it("takes 3 inputs from the user specifying side lengths and returns whether it's a triangle or not") do
test_triangle = Triangle.new(3, 7, 2)
expect(test_triangle.is_triangle?()).to eq(false)
e... | true |
95ec27551a05d543adcfe633680a24c04872d801 | Ruby | stewartmatheson/The-AI-Server | /server/lib/rdai/lib/rdai/rule.rb | UTF-8 | 774 | 2.890625 | 3 | [] | no_license | module RDAI
module Rule
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_rule
include InstanceMethods
end
end
module InstanceMethods
def fire
eval <<-EOV
#{camelize(name)}.fire
E... | true |
ddb1f814c9ea6c50cd8d61903db86d0bdc37b374 | Ruby | flyeven/rSugar | /proxy.rb | UTF-8 | 507 | 3.1875 | 3 | [] | no_license | #!/usr/bin/env ruby
#-*- coding: utf-8 -*-
Proxy = Class.new(BasicObject) do
def initialize(subject)
@subject = subject
end
def method_missing(message, *args, &block)
::STDOUT.puts "Before method called"
ret = @subject.send(message, *args, &block)
::STDOUT.puts "After method called"
ret
... | true |
92be0abc197952ffcf54bee528b59a1886428859 | Ruby | bsheehy9/ls-challanges | /medium/clock/clock.rb | UTF-8 | 1,740 | 4.375 | 4 | [] | no_license | =begin
problem:
- create clock class
- class method 'at'
- mandatory hour parameter
- optional minute parameter
- '+' and '-' methods to add minutes
- output string in 00:00 format
- 24 hour day
examples: given in tests
data:
- string output
- integer inputs
algorithm:
- create constant for ... | true |
9a6332579fa1a653cac88cff9f9cf0d56d0afc21 | Ruby | rajiv-g/devops-scripts | /influxdb-scripts/measurement-migration-script.rb | UTF-8 | 4,044 | 2.640625 | 3 | [] | no_license | require 'influxdb'
require 'json'
require 'toml'
require 'date'
config = TOML.load_file('migrate.conf')
$flag_after_rows = config['migrate']['flag_after_rows'] || 100
$start_from_previous_migration_date = config['migrate']['start_from_previous_migration_date']
$flag_rows_processed = 0
$total_rows_processed = 0
$influx... | true |
9f1460ac479cdc2d1098c4e0127f2703eeb3c149 | Ruby | RameshC1993/collections_practice-onl01-seng-ft-012120 | /collections_practice.rb | UTF-8 | 1,059 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
array.sort do |a, b|
a <=> b
end
end
def sort_array_desc(array)
array.sort do |a, b|
b <=> a
end
end
def sort_array_char_count(strings)
strings.sort do |a, b|
a.length <=> b.length
end
end
def swap_elements(array)
temp_item = array[1]
array[1] = array[2]
arr... | true |
7918bfaac7a5ae6b29e091f949d356a5ecb30753 | Ruby | Bassmint123/Ruby-and-Rails-Projects | /script8.rb | UTF-8 | 7,260 | 4.75 | 5 | [] | no_license |
# 1. A block is just a bit of code between do..end or {}. It's not an object on its own,
# but it can be passed to methods like .each or .select.
# 2. A proc is a saved block we can use over and over.
# 3. A lambda is just like a proc, only it cares about the number of arguments
# it gets and it returns t... | true |
d255f38547cbfec207610981f913ea82e6f34a4d | Ruby | megamsys/nilavu | /lib/scheduler/schedule_info.rb | UTF-8 | 2,973 | 2.625 | 3 | [
"MIT"
] | permissive | module Scheduler
class ScheduleInfo
attr_accessor :next_run,
:prev_run,
:prev_duration,
:prev_result,
:current_owner
def initialize(klass, manager)
@klass = klass
@manager = manager
data = nil
if data = $redis.g... | true |
5a1b658aa066fff809db5bc8b8c02442fa438203 | Ruby | trizen/sidef | /scripts/Tests/catalan_numbers_2.sf | UTF-8 | 134 | 2.921875 | 3 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
func c(n) is cached {
n == 0 ? 1 : (c(n-1) * (4 * n - 2) / (n + 1))
}
15.times { |i|
say "#{i}\t#{c(i)}";
}
| true |
6d707d6c6fcfc11f75d558443811e17976e1cb04 | Ruby | katymccloskey/phase-0-tracks | /ruby/hamsters.rb | UTF-8 | 1,139 | 3.984375 | 4 | [] | no_license | # ask user hamster's name
#name= gets.chomp
puts "What is your hamster's name?"
name = gets.chomp
# ask user hamster's volume level on scale of 1-10
#volume= gets.chomp
#volume= true if <=10, false if >10
puts "On a scale of 1-10, how loud is your hamster?"
volume_level = gets.chomp
volume_level.to_i
puts #{vol... | true |
fe0acad45b4d34d8e41aa106d78e2f3482d693c8 | Ruby | huberb/eulerproblems | /euler39/euler39.rb | UTF-8 | 410 | 3.28125 | 3 | [] | no_license | def solutions(p)
sol = []
(1..500).each do |i|
(1..500).each do |j|
c = p - i - j
next if c < 0
if c * c == i * i + j * j
sol << [i, j, c].sort
# puts "#{c}, #{i}, #{j}"
end
end
end
sol.uniq
end
max = []
max_index = 1
1000.times do |i|
sol = solutions(i)
if s... | true |
cb2797429e58eacfcabdabbbc9dc2c67604f16be | Ruby | MrMicrowaveOven/zadt | /spec/universe_specs/point_spec.rb | UTF-8 | 926 | 2.515625 | 3 | [
"MIT"
] | permissive | require_relative "../spec_helper.rb"
describe Point do
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
before :each do
@pointA = Point.new([5,4,3])
end
it "stores coordinates" do
expect(@pointA.coords).to eq([5,4,3])
end
it "stores the dimensions of the coordinates" do
... | true |
6a75ea1d83a665ac5dbeb0e5e6ce23194c1c2da8 | Ruby | Jaywinebrenner/Code-Review-Week-11 | /spec/models/product_spec.rb | UTF-8 | 1,409 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
describe Product do
it("titleizes the name of an product") do
product = Product.create({name: "rat milk", cost: "20", country_of_origin: "Bulgaria"})
expect(product.name()).to(eq("Rat Milk"))
end
it { should have_many(:reviews) }
it { should validate_presence_of :name }
it { s... | true |
a5908cd894d1d49e9fbc8881e6435193ac5986c0 | Ruby | poorvashelke/aA-homework | /W1D3-recursion/W1D3_Recursion.rb | UTF-8 | 2,297 | 3.6875 | 4 | [] | no_license | require 'byebug'
def range(start, last)
#base case
return [] if last <= start
[start] + range(start+ 1, last)
end
def exp_1(base, power)
return 1 if power == 0
base * exp_1(base, power - 1)
end
def exp_2(base, power)
puts " base: #{base} | power: #{power}"
return 1 if power == 0
return base if powe... | true |
0e72e4a77185db9c70d9987f4a52158200c55919 | Ruby | iwpeifer/pokemon-scraper-web-040317 | /lib/pokemon.rb | UTF-8 | 666 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Pokemon
attr_reader :id, :name, :type, :db, :hp
@@all = []
def initialize(id:, name:, type:, db:, hp: nil)
@id = id
@name = name
@type = type
@db = db
@hp = hp
@@all << self
end
def self.all
@@all
end
def self.save (name, type, db)
db.execute("INSERT INTO pokemon (name, type) VALUES (... | true |
118a36f1b6f3049165fa894282a233f28e9005dd | Ruby | frmichetti/websocket-tasks-app | /server.rb | UTF-8 | 2,048 | 2.921875 | 3 | [] | no_license | require 'em/pure_ruby'
require 'em-websocket'
require 'rx'
require 'rufus-scheduler'
EM.run do
@messages = []
@scheduler = Rufus::Scheduler.singleton
@paused = false
@times = 1
@amount = 1
EM::WebSocket.run(host: '0.0.0.0', port: 8080) do |ws|
source = Rx::Observable.from_array(@messages)
subscr... | true |
a04ce5b78f78c0fa8c7b2d6a6a1211ca3bf83041 | Ruby | thatandyrose/vending_machine | /lib/change_calculator.rb | UTF-8 | 888 | 3.109375 | 3 | [] | no_license | class ChangeCalculator
attr_reader :change
def initialize(change_required_in_pence, available_coins)
@change_required_in_pence = change_required_in_pence
@available_coins = available_coins
calculate_change if enough_coins_value?
end
def calculate_change
coins_collected = []
collected_amou... | true |
e263034b01cc89c1cd988804582be70c2df5c352 | Ruby | snailoff/knotz | /lib/knotz/template.rb | UTF-8 | 893 | 2.59375 | 3 | [
"CC0-1.0"
] | permissive | module Knotz
class Template
def initialize config
Knotz.logger.info ""
Knotz.logger.info "=== Template ==="
@config = config
@tpl = File.read Knotz.mainConfig[:template_path]
end
def render
knotFrom = !@config[:parsed][:knot_from].empty? ? "<p class=\"from\"><span class=\"glyphicon glyphicon-che... | true |
b15a4d21e269746f9b43f9ba4cbfbf42db9d136e | Ruby | thestrauss3/black-1.1.1 | /blackjack/lib/blackjack.rb | UTF-8 | 343 | 2.59375 | 3 | [] | no_license | require_relative "card"
require_relative "deck"
require_relative "dealer"
require_relative "player"
require_relative "game"
require 'pry'
deck = Deck.new
player = Player.new
dealer = Dealer.new
# Your code here...
dealer.start_game(deck, player)
game = Game.new(player, dealer, deck)
game.get_action
dealer.play(deck... | true |
4b75088b8a5f055e130cf7e96db862db02e5db3e | Ruby | dlee3427/ruby-oo-object-relationships-kickstarter-lab-yale-web-yss-052520 | /lib/project.rb | UTF-8 | 362 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Project
attr_accessor :title
def initialize(title)
@title = title
end
def add_backer(backer)
ProjectBacker.new(self, backer)
end
def find_backer
ProjectBacker.all.select { |project_backer| project_backer.project == self }
end
def backers
self.find_backer.collect {|project_b... | true |
82aa4b8de0cf95213602744818997cce409b9b01 | Ruby | maneeshacd/job_campaign | /lib/services/fetch_ads.rb | UTF-8 | 362 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
require 'faraday'
# fetch ads from external API
class FetchAds
def initialize(params)
@url = params[:url]
end
def self.call(*args)
new(*args).perform
end
def perform
resp = Faraday.get(@url)
JSON.parse(resp.body)['ads']
rescue => e
warn "Error while fetc... | true |
14998316d856959492c39461c9d048bf252d6191 | Ruby | CEsGutierrez/Hashmap-Questions | /lib/permutations.rb | UTF-8 | 608 | 3.484375 | 3 | [
"MIT"
] | permissive |
def permutations?(string1, string2)
if string1.length != string2.length
return false
elsif string1.length == 0
return true
end
checking_hash = {}
string1.each_char do |letter|
if checking_hash.has_key?(letter)
checking_hash[letter] += 1
else
checking_hash[letter] = 1
end
... | true |
9be9e3cff76415966ef72206fd0a67825808af45 | Ruby | wishcastr/wishcastr | /app/models/wish.rb | UTF-8 | 482 | 2.578125 | 3 | [] | no_license | class Wish < ActiveRecord::Base
validates :name, presence: true
has_many :products_wish
has_many :products, through: :products_wish
belongs_to :user
accepts_nested_attributes_for :products
def product_duplicate?(sku, type)
self.products.any? { |p| p.sku == sku && p.type == type }
end
def find_catc... | true |
527d96bd210bbda32fd2f3c4dd9eb6b7af362fcb | Ruby | schacon/git-db | /lib/git-db/objects/tree.rb | UTF-8 | 845 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'stringio'
class GitDB::Objects::Tree < GitDB::Objects::Base
def entries
@entries ||= begin
entries = []
stream = StringIO.new(data)
until stream.eof?
perms = read_until(stream, ' ').to_i
name = read_until(stream, 0.chr)
sha = GitDB.sha1_to_hex(stream.read(20... | true |
1e2fee56152025215b644738bffb42841ccffc83 | Ruby | youssefbenlemlih/ruby-practice | /ptp7/examples/symbol.rb | UTF-8 | 162 | 2.921875 | 3 | [] | no_license | # Author:: Youssef Benlemlih
# Author:: Jonas Krukenberg
# Definition of a symbol with interpolation
var = "a#{1 + 1}".to_sym
var2 = :"a#{2 + 2}"
puts var.inspect
puts var2.inspect
| true |
a4f6aa8b427f81b7badd4a8da5d19e1d19ad0bc2 | Ruby | GavinThomas1192/rubyOnRailsBasics | /RubyBasics/widgets.rb | UTF-8 | 914 | 4.25 | 4 | [] | no_license |
def ask(question)
# ask a question, that is a parameter
print question + " "
# implicit retun the value of the question after user types
# https://ruby-doc.org/core-2.2.0/String.html link for chomp
gets.chomp
end
def price(quantity)
if quantity >= 100
price_per_unit = 8
puts "D... | true |
2e2b815454f45462c8873f793978d208d6f21040 | Ruby | Loft47/docusign_dtr | /lib/docusign_dtr/query_param_helper.rb | UTF-8 | 3,614 | 2.625 | 3 | [
"MIT"
] | permissive | module DocusignDtr
# rubocop:disable Metrics/ClassLength
class QueryParamHelper
# rubocop:disable Naming/PredicateName
QUERY_PARAMS = {
search: :search,
count: :count,
end_date: :endDate,
start_position: :startPosition,
room_status: :roomStatus,
owned_only: :ownedOnly,
... | true |
1a91e206d32dc01c8227d673d29d05cfe66c2adc | Ruby | mwlang/tic-tac-toe | /run.rb | UTF-8 | 1,974 | 3.9375 | 4 | [] | no_license | require_relative 'game'
require_relative 'board'
require_relative 'players/player'
require_relative 'players/novice'
require_relative 'players/skilled'
module TicTacToe
POSITIONS = 9
WINS = [
[0,1,2], [3,4,5], [6,7,8],
[0,3,6], [1,4,7], [2,5,8],
[1,4,8], [2,4,6]
]
class Empty
attr_reader ... | true |
5664e184dbb49f606475b55c9445d1ecdf934681 | Ruby | kumonopanya/hi | /refe/fsdbm.rb | UTF-8 | 2,388 | 2.734375 | 3 | [] | no_license | #
# fsdbm.rb
#
# Copyright (c) 2003 Minero Aoki <aamine@loveruby.net>
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU Lesser General Public License version 2 or later.
#
require 'find'
class FSDBM
# turn on tracing only when used with refe
begin
requi... | true |
47ca89da6d291f011ada40d877d6e3b3bd10122c | Ruby | ministryofjustice/smartdown | /lib/smartdown/parser/scenario_sets_interpreter.rb | UTF-8 | 2,112 | 2.984375 | 3 | [
"MIT"
] | permissive | require "smartdown/model/scenarios/scenario_set"
require "smartdown/model/scenarios/scenario"
require "smartdown/model/scenarios/question"
module Smartdown
module Parser
class ScenarioSetsInterpreter
def initialize(smartdown_input)
@smartdown_input = smartdown_input
end
def interpret
... | true |
3183bd8b8efdb74f38c1f6ead95fc04ca493db74 | Ruby | geoiq/annotation_nation | /parrot.rb | UTF-8 | 850 | 2.71875 | 3 | [] | no_license | %w{ pp rubygems eventmachine json geoiq-gem}.each {|gem| require gem}
dataset_id = ARGV.shift
puts "Fetching dataset #{dataset_id}..."
dataset = Geoiq::Dataset.load(dataset_id)
puts "Fetching features..."
features = dataset.features
puts "Creating a destination dataset..."
target = Geoiq::Dataset.new()
target.title... | true |
26d0746bc875ea82db8acbcfaae93f44ed4eaae1 | Ruby | vincentpaca/clickinglabs_ruby | /chapter_01/code/arrays.rb | UTF-8 | 571 | 4.78125 | 5 | [] | no_license | #anything goes inside arrays, numbers, strings, symbols. Anything
array = [1, "two", :three]
#we can use the 'each' method to iterate the values inside an array.
array.each do |a|
puts a
end
#this code simply multiplies each number inside the array
numbers = [1, 2, 3] #lets initialize the numbers
new_number_array =... | true |
8ac09003a06a88ea9cb33275c0dda2077fc0733d | Ruby | EricRicketts/IntroductionToProgramming | /RubyBasics/Hashes/exercise_8_test.rb | UTF-8 | 342 | 2.78125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
class Exercise7Test < Minitest::Test
def setup
@numbers = {
high: 100,
medium: 50,
low: 10
}
end
def test_select_low_numbers
expected = { low: 10 }
@numbers.select! { |key, value| value < 25 }
assert_equal(expected... | true |
a68fe31b87b0c79724496674817abbb54d14c972 | Ruby | SpencerCDixon/SQL-Challenge | /import.rb | UTF-8 | 3,261 | 3.5 | 4 | [] | no_license | # Use this file to import the sales information into the
# the database.
require "pg"
require "csv"
require "pry"
################
### DB Conn ###
################
def db_connection
begin
connection = PG.connect(dbname: "korning")
yield(connection)
ensure
connection.close
end
end
################... | true |
4061841df221ff315f5e3f1b5ca3eaaf36758f42 | Ruby | mahtabnejad90/link-referral-web-application | /learning/playground-ruby/Intro_to_Numbers.rb | UTF-8 | 321 | 3.484375 | 3 | [] | no_license | #following are integers:
p 5.class
p 0.class
p 100.class
p -866.class
#following are floating point numbers. .next method cannot be used in floating point numbers:
p 5.987.class
p 2.71.class
p -10.11.class
#Big numbers are also classed as an integer:
p 99999999999999999999999999999999999999999999999999999999999.class... | true |
f82fe2a5d120decd384f8944910cfb4c5c0407ad | Ruby | red-data-tools/red-chainer | /lib/chainer/functions/connection/convolution_2d.rb | UTF-8 | 5,488 | 3.078125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Chainer
module Functions
module Connection
class Convolution2DFunction < Chainer::FunctionNode
attr_reader :sy, :sx, :ph, :pw, :cover_all
# Two-dimensional convolution function.
# This is an implementation of two-dimensional convolution in ConvNets.
# It takes three va... | true |
941e3299c1559f7893caeade4aadba5627324639 | Ruby | elasticstatic/mdslide | /lib/mdslide/creator.rb | UTF-8 | 1,543 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'kramdown'
require 'erb'
require 'kconv'
module Mdslide
class Creator
attr_reader :stylesheets,:scripts,:theme_stylesheets,:theme_scripts
attr_accessor :title
def initialize
@stylesheets = ['base.css']
@scripts = ['jquery.min.js','slides.js']
@theme_scripts ... | true |
528b2654cbcfc392426771042db10bab1353e462 | Ruby | jli-hashrocket/ruby-algorithms | /node.rb | UTF-8 | 150 | 3.109375 | 3 | [] | no_license | class Node
attr_reader :val
attr_accessor :left, :right
def initialize(value=nil)
@val = value
@left = nil
@right = nil
end
end
| true |
6ea3049b2e6b271f80707ab7b66a0ec38a28462c | Ruby | MSNCI17/Airfreighter-cargo-app | /app/models/shipment.rb | UTF-8 | 1,963 | 2.53125 | 3 | [] | no_license | class Shipment < ActiveRecord::Base
UNIT_CBM = 167
SL1_RATES = {
'Australia' => 30,
'Singapore/Taiwan/China' => 25,
'America' => 20,
'Europe' => 15,
}
SL2_RATES = {
'Australia' => 15,
'Singapore/Taiwan/China' => 12.50,
'America' => 10,
'Europe' => 7.... | true |
569658f5ae02ac3aea2ac6de955e2801c0ddf9cb | Ruby | HISMalawi/eMastercard2Nart | /transformers/encounters/hiv_clinic_consultation.rb | UTF-8 | 3,120 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
module Transformers
module Encounters
module HivClinicConsultation
class << self
def transform(patient, visit)
observations = [side_effects(patient, visit), on_tb_treatment(patient, visit)]
orders = [viral_load(patient, visit)]
{
... | true |
6f2148be9a4e4b4d1cb2ea6e3479ed9291210542 | Ruby | zarapeisker/want_to_know | /main.rb | UTF-8 | 661 | 2.515625 | 3 | [] | no_license | require "sinatra"
require "sinatra/reloader"
require "movies"
require "stock_quote"
require "image_suckr"
get "/" do
erb :home
end
get "/movies" do
unless params[:movie].nil?
@movie = params[:movie]
@result = Movies.find_by_title(@movie)
end
erb :movies
end
get "/stocks" do
unless params[:symbol].nil?
@sy... | true |
a071bc310b7deeb2342d8212dd28e29ba806023b | Ruby | awslabs/cloud-templates-ruby | /lib/aws/templates/utils/parametrized/constraint/not_nil.rb | UTF-8 | 1,089 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | require 'aws/templates/utils'
module Aws
module Templates
module Utils
module Parametrized
class Constraint
##
# Check if passed value is not nil
#
# === Example
#
# class Piece
# include Aws::Templates::Utils::Parametriz... | true |
c476cef40c0599958d757e18394be45d4d175b18 | Ruby | nasa/mmt | /lib/cmr/util.rb | UTF-8 | 1,999 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | module Cmr
module Util
# Times and logs execution of a block
def self.time(logger, message, &block)
start = Time.now
result = yield
ensure
if message.is_a?(Proc)
message.call(Time.now-start, result)
else
logger.info("#{message} [#{Time.now - start}s]")
end
... | true |
2fddba321433d15832a2ebb597ef624d70309d1b | Ruby | larrysass/reverse-each-word-dumbo-web-062419 | /reverse_each_word.rb | UTF-8 | 153 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(string)
words = string.split(" ")
new_array = words.collect do |w|
w = w.reverse
end
return new_array.join(" ")
end
| true |
2b801bb57cfe177cd91750674c1731d7bf87ae78 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/binary-search-tree/427254fc67f841f896fd354dfbd8b801.rb | UTF-8 | 469 | 3.46875 | 3 | [] | no_license | class Bst
attr_reader :left, :right, :data
def initialize(data)
@data = data
end
def insert(new_data)
new_data > data ? insert_on(:right, new_data) : insert_on(:left, new_data)
end
def each(&block)
@left.each(&block) if @left
yield data
@right.each(&block) if @right
end
private
... | true |
a44008c3f415298dd58edb848ee85ae6ed0cee40 | Ruby | John-Lin/kiwi-scraper | /bin/kiwicourse | UTF-8 | 1,274 | 2.734375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'digest'
require 'thor'
require 'fuzzy_match'
require 'launchy'
require 'coursesdesc' # for production
# require '../lib/coursesdesc/courses.rb' # for cmd line testing purposes
class KiwiCLI < Thor
desc 'search COURSENAME', 'Search a course on ShareCourse'
def search(coursename)
sc ... | true |
aae8a37c3397610d356102dc0f721b72da721f2e | Ruby | MsJennyGiraffe/mastermind | /lib/code_checker.rb | UTF-8 | 813 | 3.4375 | 3 | [] | no_license | require 'pry'
class CodeChecker
def initialize
guess_result = { "R" => 0, "G" => 0, "B" => 0, "Y" => 0}
end
def win?(user_guess, color_array)
if user_guess == color_array
true
else
false
end
end
def check_guess(user_guess, color_array)
check_colors(user_guess, color_array)... | true |
0e291471b4e136306063f89413917cdbe76967a9 | Ruby | SCPR/scripts | /SCPRv4/segments_by_show.rb | UTF-8 | 611 | 2.515625 | 3 | [] | no_license | require "csv"
shows = [
"brand-martinez",
"take-two"
]
low = Time.new(2012, 9, 10, 0, 0, 0) - 1
high = Time.new(2012, 12, 1, 0, 0, 0) - 1
rows = []
shows.each do |show|
program = KpccProgram.find_by_slug(show)
program.segments.where("published_at > :low and published_at <= :high", low: low, high: high).pu... | true |
1693aca8cbce39dc1801b98601cd757a727f6f80 | Ruby | jackcusick95/Homework | /W3D5/stack.rb | UTF-8 | 307 | 3.75 | 4 | [] | no_license | class Stack
def initialize(array)
@array = array
end
def push(el)
@array.push(el)
end
def pop
@array.pop
end
def peek
@array.first
end
end
stack = Stack.new([9,2,3,"hello", 5, "Jack"])
p stack.push("yoo")
p stack.pop
p stack.peek
| true |
e3ac38a31dab9ea0e02a441a382820f1cb4ce7cd | Ruby | AudTheCodeWitch/sql-library-lab-online-web-ft-071519 | /lib/querying.rb | UTF-8 | 1,718 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
# I need book.title, book.year from books
# where book.series_id = 1
# order by book.year
"SELECT title, year FROM books
WHERE series_id = 1
ORDER BY year;"
end
def select_name_and_motto_of_char_with_longest_motto
# I need character.name, charac... | true |
028d239bee07013c04ddde2256407eff36117de2 | Ruby | sisiyao/appacademy | /w2d1/chess/game.rb | UTF-8 | 521 | 2.53125 | 3 | [] | no_license | require_relative 'board'
require_relative 'piece'
require_relative 'null_piece'
require_relative 'display'
require_relative 'sliders'
require_relative 'steppers'
require 'byebug'
#require_relative 'pawns'
class Game
def initialize
@board = Board.new;
@display = Display.new(a);
end
def play
b.render
... | true |
06f41b5b94f9b16ba4c5908c58f4e17287413dcf | Ruby | uniquehash/hardRuby | /ex37.rb | UTF-8 | 2,094 | 3.671875 | 4 | [] | no_license | # ex37: Symbol Review
learnrubythehardway.org/book/ex37.html
BEGIN, run this block when the script starts, BEGIN { puts "hi" }
END, run this block when the script is done, END { puts "hi" }
alias, create another name for a function, alias X Y
and, logical and, but lower priority than &&, puts "hello" and "Goodbye"
b... | true |
0250475f6f1ceb2d8224da3838bbad72b5d1af72 | Ruby | fedeaux/brain_damage_1 | /lib/generators/brain_damage/resource/helpers.rb | UTF-8 | 1,079 | 2.59375 | 3 | [
"MIT"
] | permissive | module BrainDamage
module ResourceHelpers
attr_accessor :default_indentation
def display_attributes(attributes, options = {})
options = {
indentation: default_indentation,
join: "\n"
}.merge options
attributes.map { |attribute|
display_attribute(attribute, options[:... | true |
1e5a972b48e5fb096b5734d927bf5bd0b247a3fc | Ruby | tenfensw/dialogbind | /examples/alarmclock.rb | UTF-8 | 1,508 | 3.359375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Simple reminders app written in Ruby and DialogBind.
#
# Copyright (C) Tim K 2018-2019. Licensed under MIT License.
# This file is a DialogBind example.
require 'dialogbind'
require 'time'
# Get the name of the reminder
notification_name = guigets('What should I remind you?')
if notification_na... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.