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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
016f7d05054eed864f2cf9a3ef8977d705f8e023 | Ruby | jvalentini/korma_ruby | /korma.rb | UTF-8 | 1,813 | 2.90625 | 3 | [
"MIT"
] | permissive | module Korma
class Entity
attr_reader :tablename
attr_reader :columns
def initialize(tablename, *columns)
@tablename = tablename
@columns = columns
end
def to_s
@tablename.to_s
end
end
def select(entity, *columns)
columns = ["#{entity.tablename}.*"]
"SELECT #{c... | true |
bc6878b35383182b9fb309d5fc0da651bc8d1327 | Ruby | kkashuda/instance-methods-lab-ruby-v-000 | /lib/dog.rb | UTF-8 | 130 | 4.03125 | 4 | [] | no_license | # Dog class
class Dog
def bark
puts "Woof!"
end
def sit
puts "The Dog is sitting"
end
end
dog = Dog.new
dog.sit
| true |
044aad49fb6da5dc16c4929aa1fe2204ae9c11e1 | Ruby | olliekennedy/ruby-practice | /codewars/spec/pick_peaks_spec.rb | UTF-8 | 1,658 | 3.296875 | 3 | [] | no_license | require 'pick_peaks.rb'
describe 'pick_peaks' do
it 'should find peaks but not on the edge of the array' do
expect(pick_peaks([3,2,3,6,4,1,2,3,2,1,2,3])).to eq '{"pos"=>[3,7], "peaks"=>[6,3]}'
end
it 'should support finding peaks' do
expect(pick_peaks([1,2,3,6,4,1,2,3,2,1])).to eq '{"pos"=>[3,7], "peaks"... | true |
66413dbac2552f8f8398210d0f9e3df37ef0a969 | Ruby | ryanjwise/Example_Code | /ruby/chris-pine/ch7_try_sort.rb | UTF-8 | 892 | 4.40625 | 4 | [] | no_license | #Initialise variables
next_word = '' #Temporary variable Holding user input before passing into words array
words = [] #Array of words
array_size = 0 #Holds Overall size of array
#Output instructions and get first word
puts "Sorts input words alphabetically"
puts "Input word one at a time and push enter after each... | true |
14b6c4d24e2cb6df4f86cd57e65ed171af4bbfbc | Ruby | fsladkey/file-upload-demo | /app/models/user.rb | UTF-8 | 1,216 | 2.578125 | 3 | [] | no_license | # == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string not null
# email :string not null
# created_at :datetime
# updated_at :datetime
# country_id :integer not null
#
class User < ActiveRecord::Base
belongs_to... | true |
c43468376af2f24c7439639be8893ec3e701e30d | Ruby | olery/oni | /lib/oni/daemon.rb | UTF-8 | 5,928 | 3.3125 | 3 | [
"MIT"
] | permissive | module Oni
##
# The Daemon class takes care of retrieving work to be processed, scheduling
# it and dispatching it to a mapper and worker. In essence a Daemon instance
# can be seen as a controller when compared with typical MVC frameworks.
#
# This daemon starts a number of threads (5 by default) that will... | true |
13af55e7ebc88633bd7fc9ed213e3cfe94b6c02d | Ruby | RomanSokhan/sych | /rubywarrior/sych-beginner/environment.rb | UTF-8 | 1,617 | 3.140625 | 3 | [] | no_license | class Environment
def self.no_escape?(spaces)
next_space = spaces.first
next_space.wall? || next_space.enemy?
end
def on_all_rescued_at_dead_end(&block)
@on_all_rescued_at_dead_end = block
end
def danger(spaces, current_direction)
@spaces = spaces
@current_direction = current_direction
... | true |
30912587c0eeb9a41b615789197e705b876a96df | Ruby | m-cyx/Ruby | /LR1/pz3.rb | UTF-8 | 2,116 | 3.125 | 3 | [] | no_license | """
Спросить какой язык у пользователя любимый, в случае,
если это ruby, ответить что пользователь подлиза, иначе обязательно ответить,
что скоро будет ruby и поставить различный комментарий для каждого языка.
Рассмотреть условный оператор и разные способы его построения
(реализовать несколько коммитов для разных сп... | true |
c2f457b8902943b5e1daf9f377a2f1c8ad6ee795 | Ruby | bemky/bob_ross | /lib/bob_ross/palette.rb | UTF-8 | 5,136 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'sqlite3'
require 'fileutils'
class BobRoss
class Palette
attr_reader :path, :max_size, :purge_to
def initialize(path, cachefile, size: nil)
@path = path
@max_size = size || 1_073_741_824
@db = SQLite3::Database.new(cachefile)
@db.busy_timeout = 300
migrate
e... | true |
0f5c09ed4d6e5544f21b6dc7f834216cc0e63986 | Ruby | gwdean/o | /Interpreters/2008-Olsen/And.rb | UTF-8 | 758 | 3.0625 | 3 | [] | no_license | class And < Expression
def initialize(expression1, expression2)
@expression1 = expression1
@expression2 = expression2
end
def evaluate(dir)
result1 = @expression1.evaluate(dir)
result2 = @expression2.evaluate(dir)
(result1 & result2)
end
end
# Usage
# To find all the big MP3 files that ar... | true |
767690f6ad23c9daa0614f47175811adc9f7ead7 | Ruby | Kalakalot/media-ranker | /test/models/user_test.rb | UTF-8 | 553 | 2.515625 | 3 | [] | no_license | require "test_helper"
describe User do
before do
@user = User.new(name: "Leta LeStrange")
end
it "can be instantiated" do
user = User.create(name: "Hello I am Raccoon")
expect(user.valid?).must_equal true
end
describe 'validations' do
it 'is valid when all fields are present' do
# Act
resul... | true |
de831b4a5342bb8f66e36defe152d5e3c4965503 | Ruby | leahriffell/turing-ruby-exercises | /mythical-creatures/lib/wizard.rb | UTF-8 | 424 | 3.484375 | 3 | [] | no_license | class Wizard
attr_accessor :name, :bearded, :rested, :spells
def initialize(name, rested = true, spells = 0 , bearded: true)
@name = name
@rested = rested
@bearded = bearded
@spells = spells
end
def bearded?
@bearded
end
def incantation(spell)
"sudo #{spell}"
end
def rested?
... | true |
0142f116bbecbf32b50e88dedbcfb5f4b5c25b79 | Ruby | chickensmitten/tealeaf-PRS | /LS1_20_AssignmentPRS_Walkthrough.rb | UTF-8 | 1,306 | 4.0625 | 4 | [] | no_license | CHOICES = {'p' => 'Paper', 'r' => 'Rock', 's' => 'Scissors'}
puts "Welcome to Paper, Rock, Scissors!"
def display_winning_message(winning_choice)
case winning_choice
when 'p'
puts "Paper wraps Rock!"
when 'r'
puts "Rock smashes Scrissors!"
when 's'
puts "Scissors cuts Paper!"
end
end
loop do
begin
puts ... | true |
e69c42b91e34dd46c3c0bd41cdd3d009a1b0eb46 | Ruby | leocamelo/tic_tac_toe | /lib/tic_tac_toe/drivers/computer_driver.rb | UTF-8 | 386 | 2.9375 | 3 | [
"MIT"
] | permissive | module TicTacToe
module Drivers
class ComputerDriver
MOVES = [
self::CenterMove,
self::ToOverMove,
self::RandomMove
].freeze
def initialize(env)
@env = env
end
def perform
MOVES.find do |move|
cell = move.new(@env).call
br... | true |
89040636c6871c053fdfd2cdc41031b0e9542162 | Ruby | lulekalabs/luleka-v1 | /app/models/payment_method.rb | UTF-8 | 6,242 | 2.65625 | 3 | [] | no_license | # Encapsulates data for available payment methods and acts as a
# factory to instantiate a payment method of type:
#
# * Credit Cards (:visa, :mastercard, etc.)
# * Piggy Bank
#
class PaymentMethod < TransactionMethod
#--- constants
TRANSACTION_METHODS = [{
:type => :piggy_bank,
:active_merchant_typ... | true |
fd2cfeab4c00c88d8b2b39d1df4aba3a58722a9e | Ruby | divyasripadham/rails-blocitoffproject | /app/helpers/items_helper.rb | UTF-8 | 189 | 2.5625 | 3 | [] | no_license | module ItemsHelper
def days_left(item)
due_date = item.created_at.to_date + 7.days
(due_date < Date.today) ? 'Overdue' : distance_of_time_in_words(Date.today, due_date)
end
end
| true |
06bbeac8904cf4909381586ac9e9592d1399564b | Ruby | Truthvendor/backend_module_0_capstone | /day_6/exercises/person.rb | UTF-8 | 711 | 4.75 | 5 | [] | no_license | # Create a person class with at least 2 attributes and 2 behaviors.
# Call all person methods below the class and print results
# to the terminal that show the methods in action.
class Person
attr_accessor :first_name, :eye_color, :age
def initialize(first_name, eye_color, age)
@first_name = first_name
@e... | true |
519202573eb6b642ddac7e74f7e5cfcde1ad05ab | Ruby | jspaz/Ruby | /variables.rb | UTF-8 | 300 | 3.265625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
# Se asignan los valores a las variables
# Los nombres de las variables son sensibles a mayúsculas y minúsculas
# Los nombres no pueden: inicicar con número, tener caracteres especiales y utilizar palabras reservadas
length = 10
windth = 2
area = length * windth
puts area
| true |
13c7443029ebfd1578aaaa59b0630cb799db1dc5 | Ruby | danielcarneiro/vital_watcher | /app/models/marshalling.rb | UTF-8 | 2,224 | 2.578125 | 3 | [] | no_license | class Marshalling
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :user_id, :timestamp, :user,
:request, :response
validates :user_id, :presence => true
validates :user, :presence => true
validates :timestamp, :presence => true
... | true |
e3a58a983ed35758bd48d28a7455a08a320c54fb | Ruby | gktttw/my_one_order | /app/models/meal.rb | UTF-8 | 635 | 2.53125 | 3 | [] | no_license | class Meal < ApplicationRecord
has_many :meal_foods
has_many :foods, through: :meal_foods
# Q1 答案
def self.no_food_meal
Meal.left_outer_joins(:foods).where(meal_foods: {food_id: nil})
end
end
=begin
Q2 答案
select foods.name, count(*) as count FROM meal_foods
inner join foods on meal_foods.food_id = food... | true |
6c23debc8fd377e9e4b4d1a295de7c5de733b336 | Ruby | ScottKolo/suitesparse-matrix-collection-website | /db/collection_data/groups/Gupta.rb | UTF-8 | 2,925 | 2.796875 | 3 | [
"BSD-3-Clause",
"MIT",
"CC-BY-4.0"
] | permissive | {
name: 'Gupta',
num_matrices: '3',
notes: 'Linear programming matrices from Anshul Gupta, IBM T. J. Watson Research Center.
Discussed in "Fast and Effective Algorithms for Graph Partitioning and Sparse
Matrix Ordering," Ansul Gupta, IBM Research Division, T.J. Watson Research
Center, PO Box 218, Yorktown ... | true |
f34043d9af9f5254215d6cd5ad6b332b7ad41255 | Ruby | melatran/enigma | /test/offset_test.rb | UTF-8 | 793 | 2.84375 | 3 | [] | no_license | require './test/test_helper'
class OffsetTest < Minitest::Test
def setup
@date = Offset.new("092415")
end
def test_it_exists
assert_instance_of Offset, @date
end
def test_it_has_attributes
assert_equal "092415", @date.date
end
def test_it_can_square_date
assert_equal 8540532225, @date.... | true |
629e43368469a16f1b418d08dc30669b55b5da41 | Ruby | Smitty971/reverse-each-word-online-web-pt-090919 | /reverse_each_word.rb | UTF-8 | 129 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(string)
string = string.split(" ")
string.collect do |char|
char.reverse
end.join(" ")
end
| true |
2ff393a2f58abde145eabce700e3f5598d92b354 | Ruby | micahfy/liars-dice | /spec/login_spec.rb | UTF-8 | 919 | 2.625 | 3 | [] | no_license | require 'spec_helper.rb'
describe "starting the game", :type => :feature do
it "takes user to the gameplay page" do
visit '/'
click_link('/join')
page.should have_content 'Enter your name'
end
it "prints the users name on the gameplay page as entered on the login page" do
visit '/'
fill_in('... | true |
8ed9c190f72ba2400d4fe05c9661f6e392c93004 | Ruby | technopreneurG/nlu_adapter_ruby | /lib/nlu_adapter/intent_collection.rb | UTF-8 | 441 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'json'
# Class represents a collection of Intents
module NluAdapterIntentCollection
attr_accessor :name, :intents
# Constructor
def initialize(name, intents)
@name = name
@intents = intents
end
# Convert self to Hash
# @return [Hash] ruby hash
#
def to_h
{
:name => @name,
:intents => @int... | true |
f1eea23726f494e18f97f4de3ba5c521bc3cb9d6 | Ruby | emanon001/atcoder-ruby | /abc133/c/main.rb | UTF-8 | 198 | 2.546875 | 3 | [] | no_license | L, R = gets.split.map(&:to_i)
ans = 2 << 60
(L..([L + 2019, R - 1].min)).each do |l|
((l + 1)..([l + 1 + 2019, R].min)).each do |r|
a = l * r % 2019
ans = a if a < ans
end
end
puts ans
| true |
6d842d60e5471c735c7836a6122917563faf336d | Ruby | darrdv/ruby_fundamentals2 | /exercise7.rb | UTF-8 | 1,091 | 4.03125 | 4 | [] | no_license | #1.
# A hash representing the number of students in past Bitmaker cohorts
students = {
:cohort1 => 34,
:cohort2 => 42,
:cohort3 => 22
}
#2.
# a method that displays the name and number of students for each cohort
def display_cohort(s)
s.each do |k, v|
puts "#{k}: #{v}"
end
end
display_cohort(students)
... | true |
26917858d2ce7964d9c1d4694bea11c7d5ecb27d | Ruby | yuniegu3/FriendlyBakery | /app.rb | UTF-8 | 3,686 | 2.671875 | 3 | [] | no_license | require "sinatra"
require "sendgrid-ruby"
require_relative "desserts.rb"
include SendGrid
#home page
get '/' do
erb :index
end
#contact us page
get '/contactus' do
erb :contact
end
#contact us page email - user can email me through this email form.
post '/contact' do
@email = params[:email]
@context = params[... | true |
1210ef7de7cebc42fcd9d13719ebdf0e26b31ef8 | Ruby | RomanADavis/challenges | /euler/ruby/solved/problem_set(1-25)/problem12/solutions/solution.rb | UTF-8 | 587 | 3.96875 | 4 | [] | no_license | require "set"
# Takes several seconds. Could stand to speed up divisors in particular.
def triangle(n)
(n *(n + 1)) / 2
end
def divisors(n)
divisors = Set.new([1, n])
candidate = 2
until candidate > n**0.5
divisors += [candidate, n / candidate] if n % candidate == 0
candidate += 1
end
divisors
e... | true |
1ce58723ec7733d8f7a7305bd6696a7f24cee65b | Ruby | Monicacholico/ruby | /conditional_assignment_operator.rb | UTF-8 | 347 | 3.53125 | 4 | [] | no_license | puts true || "my"
puts false || "friendship"
puts nil || "is"
puts "not" || "often"
first = nil
puts first || "easily"
second = "earned."
puts second || "purchased"
third = false
third ||= true
puts third
fourth = "love"
fourth || "praise"
puts fourth
fifth = "takes"
fifth || "gives"
puts fifth
sixth = nil
six... | true |
80376dabeb277eec8b0a528da60f7de29c2a4377 | Ruby | PeckLiu2017/meta_programming_study | /chapter4/blocks/redflag_5/redflag.rb | UTF-8 | 907 | 2.671875 | 3 | [] | no_license | lambda {
setups = []
events = []
Kernel.send :define_method, :setup do |&block|
setups << block
end
Kernel.send :define_method, :event do |description, &block|
events << {:description => description, :condition => block }
end
Kernel.send :define_method, :each_setup do |&block|
setups.each do |setup|
... | true |
6c30960e3f48245e4f78e728eb88f39230c45105 | Ruby | MrObele/Exercism-Challenges | /ruby/sieve/sieve.rb | UTF-8 | 678 | 3.671875 | 4 | [] | no_license |
class Sieve
def initialize limit
@limit = limit
end
def primes
result = []
if @limit < 2
result
elsif @limit < 3
result = [2]
result
elsif @limit > 2
result = [2]
for i in 3..@limit do # initializes a loop ending at the limit given
checker = 0 #this c... | true |
dfe1c6c7e9eb364a28ac32188b50d2963bc22c0a | Ruby | kumaphone/kadai-ruby-oop-3 | /human.rb | UTF-8 | 278 | 2.984375 | 3 | [] | no_license | require './animal'
require './thinkable'
class Human < Animal
attr_accessor :syumi
def initialize(name, age, syumi)
self.name = name
self.age = age
self.syumi = syumi
end
include Thinkable
end
#puts Human.superclass | true |
b4e2ef443d5bb93922bed1dfbad9fc18b71e8fde | Ruby | mahendra-patil/TextFileData | /Vs_code/code.rb | UTF-8 | 688 | 3.53125 | 4 | [] | no_license | # module My
# def My.display
# puts "hello this id display function "
# end
# end
# My.display();
# arr=[5,8,5,4,6,6,8,7,2];
# # puts arr.detect{|e| arr.count(e)>1 };
# puts arr.select {|e| arr.count(e) > 1}.uniq
# class Area
# @@pie = 3.141516
# def setwidth=(value)
# @width = value
# end
# ... | true |
2356b77032288b87a7bcfb45bb7ed3672daa06f3 | Ruby | Marian-13/program_2_0 | /lib/attr_from_hash_initializer.rb | UTF-8 | 2,243 | 3.3125 | 3 | [] | no_license | # TODO Refactor
module AttrFromHashInitializer
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
# Generates instance variables and private methods for their initialization
# inside class extended by AttrFromHashInitializer
#
# ==== Atributes
#
# +*attr_names+ n... | true |
561af33a88026ace3ee3d04e523349a15a1c550c | Ruby | BosqueM/ttt-4-display-board-rb-q-000 | /lib/display_board.rb | UTF-8 | 685 | 4.15625 | 4 | [] | no_license | # Define display_board that accepts a board and prints
# out the current state.
def display_board(board) # This defines and creates a Method called "display_board"
# This Method "display_board" accepts an Argument named "board"
dash = "-----------" #variable defining the seperating das... | true |
0fef89bc7343d4ad14b89c84677e6a4615afbbd8 | Ruby | Epictetus/latinum | /lib/latinum/collection.rb | UTF-8 | 1,958 | 2.734375 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# ... | true |
37da3d2ff5b728dd37f447a343061e923378fdbc | Ruby | Chethan-rajendra/ruby_set1 | /polymorphism1.rb | UTF-8 | 739 | 3.984375 | 4 | [] | no_license | # Create a class called Animal.
# Define five other animals which should have all the properties of animal.
# Define a method which represents the noise of the animal.
class Animal
def initialize(sound)
@sound=sound
# puts @sound
end
end
class Dog< Animal
def noise
puts "#{@sound}"
end
end
class Cat< Anima... | true |
ea493261dec99f92913c0ecb608325a9290b4591 | Ruby | Shopify/cli-ui | /lib/cli/ui/formatter.rb | UTF-8 | 6,411 | 2.625 | 3 | [
"MIT"
] | permissive | # typed: true
# frozen_string_literal: true
require('cli/ui')
require('strscan')
module CLI
module UI
class Formatter
extend T::Sig
# Available mappings of formattings
# To use any of them, you can use {{<key>:<string>}}
# There are presentational (colours and formatters)
# and se... | true |
9c8316b1604aef7c3d638768137e2cb167fdfc14 | Ruby | adamcooke/documentation | /lib/documentation/search_result.rb | UTF-8 | 1,711 | 2.8125 | 3 | [
"MIT"
] | permissive | module Documentation
class SearchResult
attr_accessor :query
attr_accessor :time
attr_accessor :raw_results
attr_accessor :results
attr_accessor :page
attr_accessor :per_page
attr_accessor :total_results
def initialize
@time = nil
@raw_results = {}
@page = 1
@... | true |
d047944592cbf7da21629de1b58e58d02ebe189d | Ruby | sargurua/cli-applications-guessing-game-chicago-web-82619 | /guessing_game_cli.rb | UTF-8 | 290 | 3.859375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Code your solution here!
def run_guessing_game
num = rand(6) + 1
puts "Guess a number 1 to 6"
input = gets.chomp
case input
when "exit"
puts "Goodbye!"
when num.to_s
puts "You guessed the correct number!"
else
puts "Sorry! The computer guessed #{num}."
end
end | true |
c4dcc658691d8cd6d7b6645de0f37cf00d99e763 | Ruby | adamcolpitts/ballistiq-chain | /lib/ballistiq/chain/blockchain.rb | UTF-8 | 1,268 | 2.9375 | 3 | [
"MIT"
] | permissive | require "ballistiq/chain/block"
require "json"
module Ballistiq
module Chain
class Blockchain
attr_accessor :chain
def initialize()
@chain = [Ballistiq::Chain::Block.genesis]
end
def add_block(data)
block = Ballistiq::Chain::Block.mine_block(@chain.last, data)
@c... | true |
09fccd19eff097a76f57999ca60aaf6304767bf3 | Ruby | telads/take-away-challenge | /lib/takeaway.rb | UTF-8 | 367 | 3.3125 | 3 | [] | no_license | class Menu
def initialize
@menu = {"french fries" => "£4",
"burger" => "£8",
"pasta" => "£8",
"water" => "£1" }
end
def see
@menu
end
def select(items)
french_fries = items.count("french fries")
pasta = items.count("pasta")
"#{french_fries} x fr... | true |
7cd38ae65c040c815d2d82531d69b22281dfba4c | Ruby | deivid-rodriguez/parallel_tests | /spec/parallel_tests/grouper_spec.rb | UTF-8 | 4,700 | 2.75 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'spec_helper'
require 'parallel_tests/grouper'
require 'parallel_tests/cucumber/scenarios'
require 'tmpdir'
describe ParallelTests::Grouper do
describe '.by_steps' do
def write(file, content)
File.open(file, 'w') { |f| f.write content }
end
it "sorts features ... | true |
3bef288bab3addab9305fb85b7623c217e07ea4e | Ruby | helloRupa/Launch-School | /Intro Book/Arrays/e07.rb | UTF-8 | 404 | 4.40625 | 4 | [] | no_license | #Write a program that iterates over an array and builds a
#new array that is the result of incrementing each value in
#the original array by a value of 2. You should have two arrays
#at the end of this program, The original array and the new array
#you've created. Print both arrays to the screen using the p method ... | true |
8f7df23f379fc124cd8c32e4e1faa9e95c3ae223 | Ruby | silverballs/ruby-kickstart | /session2/notes/10-notes.rb | UTF-8 | 173 | 3.5 | 4 | [
"MIT"
] | permissive |
class Car
def set_miles(miles)
@miles = miles
end
def get_miles
return @miles
end
end
car = Car.new
car.set_miles 500
p car.get_miles
p car.instance_variables | true |
051539e1b77b2b7f8849963cdca4359ceff5eff8 | Ruby | peggycodus/clock_angle | /spec/clock_angle_spec.rb | UTF-8 | 257 | 2.703125 | 3 | [] | no_license | require 'rspec'
require 'clock_angle'
describe ('clock_angle') do
it('returns the smallest distance in degrees between the minute and hour hand given the time') do
clock_angle('12:00').should(eq(0))
end
# clock_angle('1:45').should(eq(90))
# end
end
| true |
a74422a1bfbc047d11b527ca3575567629e77bac | Ruby | Jaernbrand/party_prawn_submarine | /party_prawn_submarine/point.rb | UTF-8 | 86 | 2.59375 | 3 | [
"MIT",
"CC-BY-3.0",
"CC0-1.0"
] | permissive |
# A point consisting of a x-attribute and a y-attribute.
Point = Struct.new(:x, :y)
| true |
f17a9c36ed8b649ce6d907b5290d73351761d280 | Ruby | eLZyBee/ruby-on-the-rocks | /lib/orm_otr/associatable.rb | UTF-8 | 2,540 | 2.640625 | 3 | [] | no_license | require_relative 'searchable'
require 'active_support/inflector'
class AssocOptions
attr_accessor(
:foreign_key,
:class_name,
:primary_key
)
def model_class
@class_name.constantize
end
def table_name
model_class.table_name
end
end
class BelongsToOptions < AssocOptions
def initializ... | true |
a2b981660c7ebb49c3f5efb3b31ee4ac47afb63a | Ruby | mrdougal/house | /app/uploaders/upload/common.rb | UTF-8 | 3,421 | 2.71875 | 3 | [] | no_license | # encoding: UTF-8
module Upload
module Common
module ClassMethods
end
module InstanceMethods
# Gives the name of the file for thumbnails and previews.
# eg: thumb.png or large.jpg
#
# Note that this method is different to the parent's basename
... | true |
5c73d2bc7aee7112284764e4b311224a0204759b | Ruby | Rhoxio/interview-practice | /lib/queue.rb | UTF-8 | 750 | 3.59375 | 4 | [] | no_license | # This uses LinkedListNode
class CustomQueue
attr_reader :head, :tail
def initialize(head = nil)
@head = head
@tail = nil
end
def empty?
!@head
end
def enqueue(value)
new_node = LinkedListNode.new(value)
if @head.nil?
@head = new_node
elsif @tail.nil?
@tail = new_node... | true |
22dd7c947e30d5cb0c57654bb0ed5bf9061bee65 | Ruby | tonyg/osc | /osctest.rb | UTF-8 | 9,603 | 3.25 | 3 | [] | no_license | require 'rubygems'
require 'gosu'
require 'matrix'
class Vector
def theta
Math.atan2(self[1], self[0]) * (180 / 3.14159)
end
end
def repeat(num)
while num > 0
yield
num -= 1
end
end
class GameObject
def initialize (window, x, y, image)
@image = Gosu::Image.new(window, image, true)
@x = x
@y = y
... | true |
4ebedfa615d471a25fce336c7b2ccd0da7f55faf | Ruby | jalpher/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 594 | 4.03125 | 4 | [] | no_license | #write your code here
def echo(e)
e
end
def shout(e)
e.upcase
end
def repeat(e, t=2)
result = ""
(1..t).each do
result = result + e + " "
end
return result.strip!
end
def start_of_word(w, n)
return w[0..n-1]
end
def first_word(p)
a = p.split(" ")
return a[0]
end
def titleize(phrase)
little_... | true |
93bfd8434faf2130df52e2b60306691edabba6d6 | Ruby | romain-daversa/mars-horizon-mini-game-solver | /solver.rb | UTF-8 | 6,747 | 2.84375 | 3 | [] | no_license | require 'timeout'
module Emojifier
def convert(type)
case type
when :electricity
'⚡'
when :coms
'📻'
when :data
'💾'
when :heat
'🔥'
when :thrust
'🚀'
when :nav
'🧭'
else
" #{type}"
end
end
end
class Transformation
include Emojifier
... | true |
fbf9e502c5eec0c730e92a6d3752573349a3d603 | Ruby | team-eden/ruby-units | /spec/ruby-units/cache_spec.rb | UTF-8 | 646 | 2.53125 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/../spec_helper'
describe Unit::Cache do
subject { Unit::Cache }
let(:unit) { Unit('1 m') }
before(:each) do
subject.clear
subject.set("m", unit)
end
context ".clear" do
it "should clear the cache" do
subject.clear
expect(subject.get('m')).to be... | true |
1a204efcb87310240fee0eb97c938e28e12e8309 | Ruby | CardozoIgnacio/Ruby_Tp | /Tp8/ej_03.rb | UTF-8 | 998 | 3.171875 | 3 | [] | no_license | puts "Cree otro un nuevo archivo con nombres de personas similar al punto 1.
Luego genere un nuevo archivo que contenga la información de ambos archivos
mezclados, es decir, un dato del 1o, 1 dato del 2o, luego un dato del 1o,
luego un dato del 2o y así sucesivamente hasta completar la totalidad de
registros que s... | true |
0aac384bb96e0e79d87742325c51f80a7bce4fb9 | Ruby | greenes/environment | /bin/hbucket-sync | UTF-8 | 1,297 | 2.59375 | 3 | [
"Unlicense"
] | permissive | #!/usr/bin/env ruby
# encoding: utf-8
# Syncs two buckets from your Heroku environment.
# Usage when inside a Heroku folder:
# hbucket-sync <source-bucket-name> <target-bucket-name>
require "fileutils"
@access_key_id = %x{`which ruby` `which heroku` config:get AWS_ACCESS_KEY_ID}.to_s.chomp
@secret_access_key = %x{`w... | true |
e3776c662c42ba7ccd001f60e3f291b79aead1a0 | Ruby | SKTPausanias/discovery_piscine | /rb05/ex11/count_it.rb | UTF-8 | 135 | 2.59375 | 3 | [] | no_license | #!/usr/bin/ruby
if ARGV.size < 1
puts "none"
else
puts "parameters: " + ARGV.size.to_s
ARGV.each { |n| puts "#{n}: #{n.size}" }
end
| true |
41561eec9a6153fb9fd495f49ab7e726bea66c4a | Ruby | dhalverson/potluck | /test/potluck_test.rb | UTF-8 | 1,672 | 3.078125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/dish'
require './lib/potluck'
class PotluckTest < Minitest::Test
def test_it_exists
potluck = Potluck.new("7-13-18")
assert_instance_of Potluck, potluck
end
def test_it_has_a_date
potluck = Potluck.new("7-13-18")
assert_equal ... | true |
09ec2debb2521368536d29de77cbe8199e240a5c | Ruby | puppetlabs/puppetlabs-postgresql | /lib/puppet/functions/postgresql/postgresql_escape.rb | UTF-8 | 1,126 | 2.859375 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-free-unknown"
] | permissive | # frozen_string_literal: true
require 'digest/md5'
# @summary This function escapes a string using [Dollar Quoting](https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING) using a randomly generated tag if required.
Puppet::Functions.create_function(:'postgresql::postgresql_escape') do
... | true |
2aa0adda6def29f70ff4c654f79110564eb54625 | Ruby | abhinayak95/cricketproblem | /spec/probability_spec.rb | UTF-8 | 1,025 | 3.1875 | 3 | [] | no_license | require_relative "../probability.rb"
RSpec.describe Probability, "#get_probability" do
context "Given the initial values" do
it "return a hash with respective valuse" do
probability = Probability.new(0,1,2,3,4,5,6,7)
result = probability.get_probability()
expect(result).to eq ({
0 => 0,... | true |
6a7256cac88c5e250d410b6f4c16c5432c8161dd | Ruby | AluaBaikadamova/sql-crowdfunding-lab-online-web-pt-112618 | /lib/sql_queries.rb | UTF-8 | 1,980 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your sql queries in this file in the appropriate method like the example below:
#
# def select_category_from_projects
# "SELECT category FROM projects;"
# end
# Make sure each ruby method returns a string containing a valid SQL statement.
def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabe... | true |
6689124a3e3eaf59ddb9dff48a84403358fef1b1 | Ruby | naturalnat/reverse-each-word-online-web-ft-071519 | /reverse_each_word.rb | UTF-8 | 261 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(string)
array = string.split(" ")
array.each{ |n| puts n.reverse! }
string = array.join(" ")
end
def reverse_each_word(string)
array = string.split(" ")
array.collect { |word| puts word.reverse! }
string = array.join(" ")
end
| true |
2abc14f1d9da0be402b51b44dc92f3e5967b890d | Ruby | LouisSayers/robo-factory | /app/presenters/robot_presenter.rb | UTF-8 | 575 | 2.515625 | 3 | [] | no_license | class RobotPresenter
def initialize(robot)
@robot = robot
@configuration = configuration_for(@robot)
@statuses = statuses_for(@robot)
end
def as_json(options = {})
{
id: @robot.id,
name: @robot.name,
configuration: @configuration,
statuses: @statuses,
extinguished: ... | true |
c605e25e3a8967136503e36ee53cc634436a9a0a | Ruby | rondale-sc/barber_poll | /app/models/redis_cache.rb | UTF-8 | 542 | 2.75 | 3 | [] | no_license | class RedisCache
attr_reader :cache
def initialize(cache: $redis)
@cache = cache
end
def voted_recently?(key)
cache[key] == "true"
end
def register_vote(key)
cache.set(key, true)
cache.expireat(key, 2.hours.from_now.to_i)
end
def publish_answers(survey_id, answers)
payload = publ... | true |
96999317f376fdc3c79d87e456c36462c88b9bcd | Ruby | tinygrasshopper/temperature_converter | /spec/models/fahrenheit_spec.rb | UTF-8 | 543 | 3.109375 | 3 | [] | no_license | require 'spec_helper'
describe Fahrenheit do
it 'can be initialize with a value' do
fahrenheit = Fahrenheit.new(100.00)
expect(fahrenheit.value).to eq(100.00)
end
it 'can be converted to celcius' do
fahrenheit = Fahrenheit.new(100.00)
expect(fahrenheit.to_celcius.value).to eq(37.78)
end
i... | true |
75345e57ff26d2e1048bca2c9c22d502b87a4966 | Ruby | konokonekonokonekonokokoneko/imputation | /make_daily_file.rb | UTF-8 | 1,598 | 3.1875 | 3 | [] | no_license | # coding: utf-8
require 'optparse' #久しぶりにオプションを受け付けるですよ
# 定義ね
IN_DIR = Dir.pwd
OUT_DIR = "#{Dir.pwd}/date"
# まあ受け取るのはファイル名なんだが
params = ARGV.getopts('f:')
# track_A.csv こんな名前
file_base_name = params["f"].split(".")[0] # splitで分けちゃお。まあいいでしょ
# ファイルは全部開けないから一回開いたら変わったところで閉じよう
def get_file_pointer(file_name)
# ファイルポイ... | true |
785d37353c72855335b2c89202f42fc0391044fc | Ruby | romero-c-raul/Ruby-Small-Problems | /easy_4/pr2.1.rb | UTF-8 | 727 | 3.953125 | 4 | [] | no_license | # Following launchschool solution
=begin
1 -> st
2 -> nd
3 -> rd
0, 4..9 -> th
11, 12, 13 -> th
=end
def century(year)
if year % 100 == 0
century = year / 100
else
century = (year / 100) + 1
end
century.to_s + century_suffix(century)
end
def century_suffix(century)
last_digits = (century % 100)
... | true |
db46c0ae75d6ef2c80531e815cad3ff9a1dd2e1a | Ruby | VIMVIW/rubyrush | /steps/vcs-git/files/roll_some_dice.rb | UTF-8 | 704 | 3.328125 | 3 | [] | no_license | # encoding: utf-8
#
# Программа, выбрасывающая значение от 1 до 6 — одну игральную кость, версия 2.
# Cпрашиваем у юзера сколько кубиков кинуть.
#
# (с) rubyrush.ru
# Спрашиваем у пользователя, сколько кубиков кинуть и записываем его ответ в
# переменную number.
puts 'How many dice?'
number = gets.to_i
# С помощью мт... | true |
4bc60e342aa403df39a65f57b488915d1be4252d | Ruby | microsoftgraph/msgraph-sdk-ruby | /lib/models/access_package_resource_role_scope.rb | UTF-8 | 4,494 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'date'
require 'microsoft_kiota_abstractions'
require_relative '../microsoft_graph'
require_relative './models'
module MicrosoftGraph
module Models
class AccessPackageResourceRoleScope < MicrosoftGraph::Models::Entity
include MicrosoftKiotaAbstractions::Parsable
##
... | true |
a7042a7769b598169a30a333baa7203576c27686 | Ruby | keavy/blackbook | /lib/blackbook/importer/page_scraper.rb | UTF-8 | 2,417 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'rubygems'
gem 'mechanize', '>= 0.7.0'
require 'mechanize'
require 'generator' # for SyncEnumerator
# Patch Mechanize's broken html unescaping Mechanize 0.6.11
class WWW::Mechanize
def to_absolute_uri(url, cur_page=current_page())
unless url.is_a? URI
url = url.to_s.strip
url = URI.parse(
... | true |
69dcc31727697fe05cf956632281cb5386e5fd88 | Ruby | markmiller21/coder-byte-challanges | /ruby/longest_word.rb | UTF-8 | 336 | 3.359375 | 3 | [] | no_license | def LongestWord(sen)
alph = 'abcdefghijklmnopqrstuvwxyz'
words = sen.split
longest = ['a',0]
words.each do |word|
count = 0
a = 0
while a < word.length
count += 1 if alph.include? word[a]
a += 1
end
if count > longest[1]
longest = [word,count]
end
end
return longest... | true |
6745d5397caedf7612b588f325a9f66e9390a5ca | Ruby | rtyler/sonomafire | /airtable-scripts/process-pharmacies | UTF-8 | 636 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'colorize'
require 'csv'
firstRow = true
phoneIndex = nil
addressIndex = nil
lastUpdatedIndex = nil
s = CSV.generate do |csv|
CSV.parse(STDIN.read) do |row|
if firstRow
phoneIndex = row.find_index 'Phone'
addressIndex = row.find_index 'Address'
lastUpdatedIndex = ... | true |
91949b26095a5d89602b9937c67e4239a7ecb307 | Ruby | KaoruDev/ruby-mud | /spec/pick_character_spec.rb | UTF-8 | 528 | 2.625 | 3 | [] | no_license | require_relative "./spec_helper.rb"
RSpec.describe PickCharacter do
describe '.for_player' do
it 'will allow user to pick from a list' do
stub_prompter(:output, 1)
expect(PickCharacter.for_player).to be_instance_of(PlayerCharacters::Elf)
end
end
describe '.for_enemy' do
it 'will randomly... | true |
4ef23406e51f2fca6dac8a91cc595c72251669e1 | Ruby | tomaskubala/simple_action | /spec/service_spec.rb | UTF-8 | 5,414 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'fixtures/service_spec_class'
describe SimpleAction::Service do
describe "class_methods", class_methods: true do
describe "#model_name", model_name: true do
it "has correct model name" do
ServiceSpecClass.model_name.should eq("ServiceSpecClass")
end
end
... | true |
5fe4b30b3a872a3a4c31c322e09457e4498d1111 | Ruby | joshdales/15-11-Reinforcing-Exercise | /test_team.rb | UTF-8 | 332 | 2.6875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './team.rb'
class TestTeam < MiniTest::Test
def setup
@team = Team.new('tree', 13, 'Jill, Jack, Jane, Joe')
end
def test_to_hash
result = @team.to_hash
expected = {team_name: 'tree', level: 13, points: 0}
assert_equal expected, result
... | true |
e2518addd16fa59353dea64b7ab21d898ac7a2b4 | Ruby | grooble/koala | /fb_02_vn.rb | UTF-8 | 997 | 2.53125 | 3 | [] | no_license | require 'koala'
require 'json'
require 'fileutils'
require 'date'
require_relative 'post'
oauth_access_token = "EAACEdEose0cBAHx5dbZAg3j7oKROEEZBZBX2lZCmFXt9S6u0T3jIQvBX7FJSmiExamo1Pg9s4Np9dXM5gg2ePVu5Qa7IZC2VrfmiDaEgkZAKVU2vqmfahDndAs4lZCgZAP1kYkOixTmcLYPTl5D8iymUVV9xooaSgN0HggWNZAYVYzt6KsB0q46INoEZAehctQIRJOzO9uCP02... | true |
ae59700699c1bf8a82798b16748fe89e589c178c | Ruby | faustiantech/ruby-enumerables-generalized-map-and-reduce-lab-dc-web-012720 | /lib/my_code.rb | UTF-8 | 354 | 3.203125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Your Code Here
def map(source)
result = []
i = 0
while i < source.count do
result.push(yield(source[i]))
i += 1
end
result
end
def reduce(source,start=nil)
if start
result = start
i = 0
else
result = source[0]
i = 1
end
while i < source.length
result = yield(result, source... | true |
d7fc1b6a834e6351530fb69df20d53e0713b4a75 | Ruby | gijolopez/flashcards | /lib/guess.rb | UTF-8 | 443 | 3.09375 | 3 | [] | no_license | require './lib/card'
class Guess
attr_reader :response,
:card,
:feedback
def initialize(response, card)
@response = response
@card = card
@feedback = feedback
end
def correct?
if @response == @card.answer
true
else
false
end
... | true |
d0b814ce32005b56773e3fe039bd802d505004ce | Ruby | Jimbob2265/tic-tac-toe-rb-q-000 | /bin/tictactoe | UTF-8 | 220 | 3.0625 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative '../lib/tic_tac_toe'
# Code your CLI Here
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
puts "Welcome to Tic Tac Toe!"
display_board(board)
# Execute the program
play(board)
| true |
526b73f5659e8b44f8a9143834ce14f7bb844acb | Ruby | siakaramalegos/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 493 | 3.78125 | 4 | [] | no_license | def echo word
word
end
def shout word
word.upcase
end
def repeat word, number = 2
result = ''
number.times { result += word + ' '}
result.strip
end
def start_of_word word, characters
word[0, characters]
end
def first_word phrase
phrase.split(' ').first
end
def titleize phrase
do_not_cap = ['the', '... | true |
e004bb4c17fa201adea26cf462bc35c6492bf9d9 | Ruby | JazziJazz/ruby-projects | /Exercícios/[019] — Sorteando valores na tabela.rb | UTF-8 | 232 | 3.875 | 4 | [
"MIT"
] | permissive |
print("Bem-vindo! Digite o nome de quatro alunos para apagar o quadro negro, iremos sortear apenas um!\n")
students = [gets.chomp, gets.chomp, gets.chomp, gets.chomp]
puts("O aluno(a) sorteado foi o(a): #{students[rand(0..3)]}.")
| true |
958f3e93c739cbc06df314ddcb99c354e29a2f56 | Ruby | hihilisk/study | /hexlet/ruby_introduction/lesson_9.rb | UTF-8 | 212 | 3.15625 | 3 | [] | no_license | def result(a, b, c, d)
# BEGIN (write your solution here)
if a === c && b === d
return 2
elsif a > b && c > d or a < b && c < d or a === b && c === d
return 1
else
return 0
end
# END
end
| true |
368ec287c0adabee60554e9f348862d858928d70 | Ruby | uniaquinas/Bus-Bunching | /chart_transitions_demo/tools/parse_311.rb | UTF-8 | 1,834 | 3.234375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'time'
require 'date'
require 'json'
input_filename = ARGV[0]
output_filename = File.join(Dir.pwd, "requests.json")
start = Time.now
start_date = DateTime.new(2012, 10, 14)
end_date = DateTime.new(2012, 11, 17)
date_range = (start_date..end_date)
def date_string datetime
datetime.st... | true |
8c4d8df73b8c165380305d4b7b735948dcd663c4 | Ruby | rdbms-at-twitter/ruby | /sample_scripts/error_raise.rb | UTF-8 | 698 | 2.75 | 3 | [] | no_license | #irb(main):001:0> require './error_raise.rb'
#This is executed every time
#TypoError: Please check spell
# from /home/ec2-user/git/ruby/error_raise.rb:5:in `rescue in <top (required)>'
# from /home/ec2-user/git/ruby/error_raise.rb:8:in `<top (required)>'
# from /usr/share/rubygems/rubygems/core_ext... | true |
17e5bc1173689f533bfac06014d5f5bf5aa390b5 | Ruby | randallreedjr/cln | /craigslist_notifier.rb | UTF-8 | 222 | 3.0625 | 3 | [] | no_license | require_relative 'craigslist_scraper.rb'
def run()
city_urls = scrape()
puts "Please select city:"
city_name = gets.chomp
if city_urls[city_name.downcase]
puts city_urls[city_name.downcase]
end
end
run()
| true |
edbc2f1ef4420a4cd163382fe0b0eddcac0b49c2 | Ruby | burnt43/asterisk-config | /lib/asterisk-config.rb | UTF-8 | 5,463 | 2.921875 | 3 | [] | no_license | module AsteriskConfig
module Category
class Base
attr_reader :full_name
def initialize(full_name)
@full_name = full_name
@attrs = {}
end
# instance methods
# State Altering Methods
def add_attr(name, value)
attr_name = ActiveSupport::Inflector.undersc... | true |
c30aaebd447d9484f14a2936e9e8bddef3c675ab | Ruby | erinmorrissey/launch-school | /intro-to-programming/methods.rb | UTF-8 | 727 | 4.6875 | 5 | [] | no_license | # Methods — Exercises
# 1
def greeting(name)
"Hi, " + name
end
puts greeting("Erin")
# 2
=begin
1. x = 2 => 2
2. puts x = 2 => nil
3. p name = "Joe" => "Joe"
4. four = "four" => "four"
5. print something = "nothing" => nil
=end
# 3
def multipl... | true |
9285ada54c0fa13a193b744ec4d4dfe462728baa | Ruby | billguy/kj | /lib/kj/verse.rb | UTF-8 | 3,179 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require_relative 'base'
module Kj
class Verse < Base
attr_accessor :id, :chapter_id, :number, :page
attr_writer :chapter
def initialize(args)
args.each do |k,v|
instance_variable_set("@#{k}", v) unless v.nil?
end
end
def title
"#{book_name} #{chapter_number}:#{number... | true |
360823bdf328dddecaefc20a6f0fa9321e69893e | Ruby | saturnflyer/mutant | /lib/mutant/mutation.rb | UTF-8 | 2,070 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Mutant
# Represent a mutated node with its subject
class Mutation
include AbstractType, Adamantium::Flat, Equalizer.new(:sha1)
# Initialize mutation object
#
# @param [Subject] subject
# @param [Rubinius::Node::AST] node
#
# @return [undefined]
#
# @api private
#
... | true |
2fa108d8ed06c538747ab155486fcb8330f834d7 | Ruby | rruy/Validator | /lib/validation/rule/phone.rb | UTF-8 | 780 | 3.234375 | 3 | [
"ISC"
] | permissive | module Validation
module Rule
# Phone rule
class Phone
# params can be any of the following:
#
# - :format - the phone number format
#
# Example:
#
# {:format => :america}
def initialize(params = {:format => :america})
@params = params
end
... | true |
e7f400a58f5dc1589e528a484c5d98a8de39b398 | Ruby | vxvinod/Learn-Ruby | /proc-lambda/return_proc.rb | UTF-8 | 464 | 3.59375 | 4 | [] | no_license | def ret_proc
Proc.new{return "i m inside proc"}.call #here when return statement is present inside the proc it comes out of the block immediately
return " i m inside proc method"
end
puts ret_proc
#Choices, choices
#Let’s summarize all the different ways in which blocks can be created in Ruby that w... | true |
22ea4937bbd34fbea637ec3231ce9499a839a860 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/trinary/ca1b16e26c944325acef8cc467d0ebab.rb | UTF-8 | 230 | 3.28125 | 3 | [] | no_license | class Trinary
def initialize value
@trinary = value.match(/^[012]+$/) ? value.reverse : 0
@length = value.length
end
def to_decimal
[*0...@length].reverse.map { |i| @trinary[i].to_i * 3**i}.inject(:+)
end
end
| true |
f44e2d105e2bfbf9ea54a232551a2eb629449506 | Ruby | kuccho524/git-practice1 | /toshi.rb | UTF-8 | 549 | 3.921875 | 4 | [] | no_license | puts "数値を入力してください"
year = gets.to_i
showa = year - 1925
heisei = year - 1988
reiwa = year - 2018
if year == 1926
puts "#{year}年は昭和元年です"
elsif year > 1926 && year < 1989
puts "#{year}年は昭和#{showa}年です"
elsif year == 1989
puts "#{year}年は平成元年です"
elsif year > 1989 && year < 2019
puts "#{year}年は平成#{heisei}年です"
elsif... | true |
58169b97d220dbdd69c8c3f6560278e0307ce2bd | Ruby | Timetastic/slate | /vendor/ruby/2.7.0/gems/hamster-3.0.0/spec/lib/hamster/experimental/mutable_set/delete_spec.rb | UTF-8 | 835 | 2.515625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | require "spec_helper"
require "hamster/experimental/mutable_set"
describe Hamster::MutableSet do
let(:mutable) { Hamster::MutableSet[*values] }
describe "#delete" do
let(:values) { %w[A B C] }
let(:delete) { mutable.delete(value) }
context "with an existing value" do
let(:value) { "B" }
... | true |
81b78ed0b7dc06f2c85ac6b8b1b98bbef37cde40 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/rna-transcription/a9886e5394ea4db78f9ec7e1c25dbb00.rb | UTF-8 | 427 | 3.203125 | 3 | [] | no_license | class NucleicAcid
attr_reader :sequence
def initialize(sequence)
@sequence = sequence.to_s.upcase
end
def to_str
"#{sequence}"
end
def == string
to_str == string
end
end
class RibonucleicAcid < NucleicAcid
def to_dna
DeoxyribonucleicAcid.new to_str.gsub('U', 'T')
end
end
class... | true |
10a8183fb0b562b800ec4f7dcae8db361e5b6314 | Ruby | vsuzdaltsev/algos | /balanced_parentheses.rb | UTF-8 | 692 | 3.71875 | 4 | [] | no_license | # frozen_string_literal: true
require 'set'
def balanced?(string)
return false if string.length.odd?
return false if string =~ /[^()]/
opening = '('
closing = ')'
string.chars.each_with_object([]) do |sym, stack|
if sym.eql?(opening)
stack << closing
else
return false unless stack.pop... | true |
aac4cafaa18364485fd9cff0b5f63a4f478ee855 | Ruby | cielavenir/procon | /codeforces/tyama_codeforces714B.rb | UTF-8 | 143 | 2.84375 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
gets
a=gets.split.map(&:to_i).group_by{|e|e}.map(&:first).sort
puts a.size<=2 || (a.size==3&&a[2]-a[1]==a[1]-a[0]) ? :YES : :NO | true |
794b31da44170f37cf7d2c39a90eec0ff4eb21d4 | Ruby | simokh/programming-univbasics-3-build-a-calculator-lab-nyc-web-012720 | /lib/math.rb | UTF-8 | 376 | 3.078125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def addition(num1, num2)
num1 + num2
end
addition(5,4)
def subtraction(num1, num2)
num1 - num2
end
subtraction(10,5)
def division(num1, num2)
num1 / num2
end
division(50,2)
def multiplication(num1, num2)
num1 * num2
end
multiplication(4,30)
def modulo(num1, num2)
num1 mod num2
end
module(34,5)
end
d... | true |
29f7574f84ebe10c0e276a410b10ace6b771c508 | Ruby | ricardo39985/stock_scraper | /lib/interface.rb | UTF-8 | 4,277 | 3.421875 | 3 | [
"MIT"
] | permissive |
class RunScrape
def initialize
welcome
pages
stocks(@pages_to_scrape)
main_loop
exit_screen
end
def main_loop
input = ''
while input != 'exit'
puts Url.main_menu.colorize(String.colors[rand(16)])
puts "**************************************\n".colorize(:blue)+"Below is a... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.