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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1283993abf88fbc6a2a050ca418cfef2bb7ec5e5 | Ruby | Mariana-21/Enigma | /lib/encrypt.rb | UTF-8 | 505 | 2.9375 | 3 | [] | no_license | require './lib/enigma'
@enigma = Enigma.new
message = File.open(ARGV[0], "r")
incoming_text = message.read
encrypt = @enigma.encrypt(incoming_text, '15234', '020320')[:encryption]
key = @enigma.encrypt(incoming_text, '15234', '020320')[:key]
date = @enigma.encrypt(incoming_text, '15234', '020320')[:date]
new_message ... | true |
2c07d596e166fc02705e99ccb745ce5d23b55421 | Ruby | y10k/ruby-japanize | /misc/dump_lib.rb | UTF-8 | 8,716 | 2.53125 | 3 | [
"MIT"
] | permissive | #!/usr/local/bin/ruby
# -*- coding: utf-8 -*
require 'japanize'
要求 'optparse'
要求 'warning'
要求 'yaml'
日本語の別名が未定義 = 偽値
選択肢 = OptionParser.新規
選択肢.on('--not-defined-ja', '日本語の別名が未定義の操作だけを抽出') {
日本語の別名が未定義 = 真値
}
選択肢.parse!
組の表 = {}
部の表 = {}
例外の表 = {}
名前の付いた組や部に一致する正規表現 = /\A [A-Z]/x
組み込みではない組や部に一致する正規表現の一覧 = [
... | true |
15679441ebbc4047506bad164a424d9a118e0121 | Ruby | JerryMtezH/codea_camp | /EtapasDelDesarrolloHumano.rb | UTF-8 | 250 | 3.625 | 4 | [] | no_license | print "¿Cual es su edad? "
edad = gets.to_i
case edad
when 0..6
puts "Infancia"
when 7..12
puts "Niñez"
when 13..20
puts "Adolescencia"
when 21..25
puts "Adolescencia"
when 26..60
puts "Adultez"
else
puts "Ancianidad"
end | true |
ea86caf0c2072e2e6d1d0330b6bfc2d3544e06c2 | Ruby | theomoji/prime-ruby-dumbo-web-091718 | /prime.rb | UTF-8 | 314 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Add code here!
def prime?(num)
if (num < 2)
return false
else
(2...num).each do |factor|
if (num % factor == 0)
return false
end
end
end
return true
end
#A prime number is a whole number greater than 1 whose only factors are 1 and itself.
# if num is 10, 10/2 = 5.
| true |
f22d5fb62dcd18d27cc3b35364c1604ca1b15aff | Ruby | ilri/ckm-cgspace-rest-api | /app/controllers/items_controller.rb | UTF-8 | 6,932 | 2.703125 | 3 | [] | no_license | class ItemsController < ApplicationController
=begin
@api {get} /items/ Request CGSpace Items
@apiName GetItems
@apiGroup Item
@apiVersion 0.2.0
@apiDescription Use this endpoint to fetch items from [CGSpace](https://cgspace.cgiar.org/). It allows querying
for items using the following options:
- **Community** - the... | true |
4091346a3479d00b0ec2c37f0f02295b6cd0b015 | Ruby | charlesbjohnson/super_happy_interview_time | /rb/lib/leetcode/lc_206.rb | UTF-8 | 1,193 | 3.3125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module LeetCode
# 206. Reverse Linked List
module LC206
# Description:
# Reverse a singly linked list.
#
# Follow Up: A linked list can be reversed either iteratively or recursively. Could you implement both?
#
# Examples:
# Input: head = [1, 2, 3, 4, 5]
... | true |
caec1faa8589e2b1d4bbf787292dc8861e890bd8 | Ruby | sport996/practice-w04d05-ruby | /blog_post.rb | UTF-8 | 680 | 3.5625 | 4 | [] | no_license | ##
# TODO: Add Comments to BlogPost Class
class BlogPost # Declaring the setters and getters for the class properties
attr_reader :title, :content, :owner
# initializing the class properties
def initialize(title, content, owner = nil)
@title, @content, @owner = title, content, owner
end
# method edit wil... | true |
3ab9b4f3302dbae3c339efd0c16af8346c750493 | Ruby | sharpstone/heroku-bouncer | /lib/heroku/bouncer/decrypted_hash.rb | UTF-8 | 897 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'heroku/bouncer/lockbox'
# Encapsulates encrypting and decrypting a hash of data. Does not store the
# key that is passed in.
class Heroku::Bouncer::DecryptedHash < Hash
Lockbox = ::Heroku::Bouncer::Lockbox
def initialize(decrypted_hash = nil)
super
replace(decrypted_hash) if decrypted_hash
end... | true |
f3b0c2a30e099cf3f8beeda91e86f771e2ff2e04 | Ruby | AgileVentures/shf-project | /app/models/concerns/ordered_ancestry_entry.rb | UTF-8 | 11,574 | 3.265625 | 3 | [
"MIT"
] | permissive | require 'active_support/concern'
#--------------------------
#
# @module OrderedAncestryEntry
#
# @desc Responsibility: Abstract class for objects with _ordered_ nested
# descendents using the ancestry gem.``
# Ordering the descendents is the main difference between this and a 'typical'
# class that uses the ancestry ... | true |
378756ac0701001c40969e4b780f226e8694fb6b | Ruby | jhack32/team-a1 | /db/seeds.rb | UTF-8 | 791 | 2.5625 | 3 | [
"MIT"
] | permissive | user01 = User.create( username: "Albert", password: "Albert")
user02 = User.create( username: "Bertha", password: "Bertha")
survey01 = Survey.create(title: "Test Survey 01", description: "A test survey.", user_id: user01.id )
survey01.questions.create(text: "What is your favorite color?")
survey01.questions.create( t... | true |
00fb2a06e10df4ddd22549c8d304544ce5e91019 | Ruby | bfirestone23/rate-a-movie-2 | /app/models/genre.rb | UTF-8 | 241 | 2.640625 | 3 | [] | no_license | class Genre < ApplicationRecord
has_and_belongs_to_many :movies
def slug
name.downcase.gsub(" ", "-")
end
def self.find_by_slug(slug)
Genre.all.find do |u|
u.slug == slug
end
end
end
| true |
07b6cf1e65b81c76ca934697a30db4aba5dd7e24 | Ruby | rusdec/thinknetica | /Lesson_2/Excercise_6.rb | UTF-8 | 1,950 | 3.6875 | 4 | [] | no_license | =begin
Сумма покупок. Пользователь вводит поочередно название товара,
цену за единицу и кол-во купленного товара (может быть нецелым числом).
Пользователь может ввести произвольное кол-во товаров до тех пор, пока
не введет "стоп" в качестве названия товара. На основе введенных данных требуетеся:
1. Заполнить и вывес... | true |
0f782a6053a26804bfaa2ba3085a03a76b42b381 | Ruby | andrustory/looping-while-until-onl01-seng-pt-041320 | /lib/until.rb | UTF-8 | 122 | 2.84375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_until
levitation_force= 6
until levitation_force == 10
puts "Wingardium Leviosa"
levitation_force += 1
end
end
| true |
9f15465c6a7f1e327cb2197fd2731254d8110888 | Ruby | MarcosX/exercism-track | /ruby/pangram/pangram.rb | UTF-8 | 312 | 3.34375 | 3 | [] | no_license | module BookKeeping
VERSION = 3
end
class Pangram
TOTAL_AMOUNT_OF_LETTERS = 26
def self.pangram?(phrase)
count_unique_letters(phrase) == TOTAL_AMOUNT_OF_LETTERS
end
private
def self.count_unique_letters(phrase)
phrase.downcase.split('').select {|char| char =~ /[a-z]/}.uniq.size
end
end
| true |
6b688c718d73afe8ff72d7801adc92050c9fbd47 | Ruby | rmpadsala/primes_multiplication_table | /test/n2_generate.rb | UTF-8 | 372 | 3.234375 | 3 | [] | no_license | # HalfN2Generate class generates complete multiplication table
# Running time for this method is O(N^2)
module Test
class N2Generate
def initialize(prime_ary)
@prime_ary = prime_ary
end
# returns complete matrix multiplication 2d array
def matrix
@prime_ary.map.with_index { |x,i| @prime_a... | true |
0b8a00ed606550792940d0cf0dd4bd79460e6fb1 | Ruby | MBennettLowe/RoR-Prepwork | /hashes_ex3.rb | UTF-8 | 556 | 4.71875 | 5 | [] | no_license | #3.Using some of Ruby's built-in Hash methods, write a program that loops through a hash and prints all of the keys. Then write a program that does the same thing except printing the values. Finally, write a program that prints both.
family = { uncle: "bob", brother: "joe", cousin: "steve", aunt: "Terri"}
p fa... | true |
66512bcf9cc268031f1372b18716bd179c1ddf84 | Ruby | craigw/clirc | /log_watcher.rb | UTF-8 | 3,256 | 2.546875 | 3 | [] | no_license | #! /usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'socket'
CLIRC_DIR = ENV['HOME'] + '/.clirc'
module Subversion
def Subversion.client_binary
"/opt/local/bin/svn"
end
end
class Commit
def initialize(fragment)
@fragment = fragment
end
def to_s
"#{author_name} committed r#{revis... | true |
04786098b9a640aedcff2734465feba5cfdb896b | Ruby | mmrshk/bookstore | /app/models/credit_card.rb | UTF-8 | 673 | 2.53125 | 3 | [] | no_license | class CreditCard < ApplicationRecord
REGULAR_EXPESSION = {
name: /\A[a-zA-Z]*\s*[a-zA-Z]*\z/,
expiration_month_year: /\A((0[1-9])|(1[0-2]))[\/]*((1[5-9])|(2[0-3]))\Z/
}.freeze
belongs_to :user, optional: true
has_many :orders, dependent: :destroy
validates :name, :card_number, :cvv, :expiration_mont... | true |
d3ddc0edb21ba4ddfef6b503152f66659beffc18 | Ruby | FairyFali/RotChat | /app/controllers/machine_messages_controller.rb | UTF-8 | 3,311 | 2.71875 | 3 | [] | no_license | require 'net/http'
require 'uri'
require 'json'
require 'addressable/uri'
# 用户和机器人对话的controller
class MachineMessagesController < ApplicationController
before_action :authenticate_user! # 這個是 devise 提供的方法,先檢查必須登入
# 创建用户消息,同时发送给机器人,接受机器人传过来的消息
def create
# 接收用户发来的消息
user_id = current_user.id
machine_id = par... | true |
12497b2aee309b09d5f63c7cfb0c14bc0e76a27d | Ruby | mariavaghani/W4D5 | /big_o.rb | UTF-8 | 1,349 | 4.0625 | 4 | [] | no_license |
def my_min(arr)
min_num = arr.first
arr.each_with_index do |ele1, idx1|
arr.each_with_index do |ele2, idx2|
min_num = [ele1, ele2, min_num].min
end
end
min_num
end
# PHASE 2 O(n)
def my_min(arr)
min_ele = arr.first
arr.each_with_index do |ele1, idx1|
if ele1 < mi... | true |
91d75a3b2d92b81fa95104af718e6db9afa81f5a | Ruby | MIKEALGEE/ruby_functions_test | /ruby_functions_practice.rb | UTF-8 | 1,824 | 3.875 | 4 | [] | no_license | def return_10()
return 10
end
def add(first_number, second_number)
return first_number + second_number
end
def subtract(num1, num2)
return num1 - num2
end
def multiply(firstnum , secondnum)
return firstnum * secondnum
end
def divide(num1, num2)
return num1/num2
end
def length_of_string(str)
return str.lengt... | true |
2827cef3b2a1e84ceb0a91bdbaf08b9b399838d3 | Ruby | jamelablack/tealeaf | /2ndCourse/Lesson_1/Layouts_Rendering.rb | UTF-8 | 9,261 | 3.015625 | 3 | [] | no_license | http://guides.rubyonrails.org/layouts_and_rendering.html
2 Creating Responses
From the controller's point of view, there are three ways to create an HTTP response:
Call render to create a full response to send back to the browser
Call redirect_to to send an HTTP redirect status code to the browser
Call head to create... | true |
c59056e4eef237b1aeeb6509ce968cbe872bd17c | Ruby | charlie-galb/oyster_1 | /spec/oystercard_spec.rb | UTF-8 | 1,311 | 2.96875 | 3 | [] | no_license | require 'oystercard'
describe Oystercard do
describe '#initialize' do
it 'should have balance of 0 on initialization' do
expect(subject.balance).to eq(0)
end
end
describe '#top_up' do
it 'adds to the balance of the card' do
subject.top_up(5)
expect(subject.balance).to eq(5)
end
... | true |
f43ae39b37914b92a50fde5cb2ff6d96bc932c0e | Ruby | asmatameem/algos | /chain.rb | UTF-8 | 231 | 3.3125 | 3 | [] | no_license | def solution(a)
result = 10000000
p = 1
q = 3
while q < a.size - 1
result = [result, a[p] + a[q]].min
if a[p] > a[q - 1]
p = q - 1
end
q += 1
end
result
end
a = [5, 2, 4, 6, 3, 7]
puts solution(a) | true |
5afd6162aeeedf7e67cc7106a21fda54eb38a2da | Ruby | JulissaJ/property_management | /spec/features/user_adds_a_building_owner_spec.rb | UTF-8 | 1,384 | 2.625 | 3 | [] | no_license | require 'spec_helper'
feature 'real estate associate adds a new building owner', %q{
As a real estate associate
I want to record a building owner
So that I can keep track of our relationship with owners
} do
# Acceptance Criteria:
# I must specify a first name, last name, and email address
# I can optionally s... | true |
8c3110345d26ee37d5e939ecda07c567a40bccd7 | Ruby | htwang14/hw-acceptance-unit-test-cycle | /rottenpotatoes/app/controllers/movies_controller.rb | UTF-8 | 2,979 | 2.515625 | 3 | [] | no_license | class MoviesController < ApplicationController
def movie_params
params.require(:movie).permit(:title, :rating, :description, :release_date, :director)
end
def show
id = params[:id] # retrieve movie ID from URI route
@movie = Movie.find(id) # look up movie by unique ID
# will render app/views/m... | true |
80fb042973da6ce48e123b1ad7afa495332d3409 | Ruby | migs-dc/W4D1 | /knights_travails/KnightPathFinder.rb | UTF-8 | 3,357 | 3.71875 | 4 | [] | no_license | require_relative "./00_tree_node.rb"
class KnightPathFinder
attr_reader :considered_positions, :root
MOVES = [
[-1, 2],
[1, 2],
[-2, 1],
[1, -2],
[2, 1],
[2, -1],
[-2,-1],
[-1,-2]
]
def self.valid_moves(pos)
row, col = pos... | true |
48b5ef5c04d0167874a5bb2ffbad73dfe40086dc | Ruby | nicholaides/minty | /lib/minty/cli/transactions.rb | UTF-8 | 819 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'text-table'
require 'minty/utils'
require 'minty/cli/command'
module Minty
class CLI
class Transactions < Command
banner "Usage: minty accounts [options]"
option :count,
:short => "-c COUNT",
:long => "--count COUNT",
:default => 20,
:description => "Number ... | true |
c3f9da0b8f2f79ef9454d69354133b5c7172241a | Ruby | Loft47/docusign_dtr | /lib/docusign_dtr/auth/error.rb | UTF-8 | 1,596 | 2.671875 | 3 | [
"MIT"
] | permissive | module DocusignDtr
module Auth
class Error
def initialize(response:)
@response = response
end
def build
return nil if @response.code == 200
raise exception.new(standard_error_message)
end
def exception
case @response.code
when 400
... | true |
f181103f6f7ae442b2d690d0d305ec305e96afff | Ruby | AFronczak/week-2-day-1 | /homework.rb | UTF-8 | 729 | 4.375 | 4 | [] | no_license | # Your goal for tonight is to create a program to keep track of user input.
# You will repeatedly ask the user to enter a number,
# and as long as the user types a number and hits enter, you will ask again.
# If the user hits enter on a blank line (without typing a number first),
# this means that the user is finished.... | true |
d8e1f592c9fd2b2394f1aae5dc88e2f6867ffbdf | Ruby | sharma7n/HackerRank | /Ruby/methods/methods_keyword_arguments.rb | UTF-8 | 781 | 3.828125 | 4 | [
"MIT"
] | permissive | def to_celsius(temperature, input_scale: 'celsius')
if input_scale == 'celsius'
temperature
elsif input_scale == 'fahrenheit'
(temperature - 32) / 1.8
elsif input_scale == 'kelvin'
temperature - 273.15
else
raise "Unknown Temperature Input Scale"
end
end
def from_cel... | true |
63d00a3f1a14b4988be44a6da096ae1762fb2159 | Ruby | konradszydlo/ruby-bootcamp | /exercise-12/linguine/spec/main_spec.rb | UTF-8 | 4,260 | 2.96875 | 3 | [] | no_license | require_relative '../main'
describe Linguine do
let(:env) { {'PATH_INFO' => '/home.fr', 'REQUEST_METHOD' => 'GET'} }
let(:home_data) { ["welcome:Hi\n", "first_para:Our company is based in Leeds.\n", "second_para:We specialise in doing funny things.\n", "third_para:Our company is based in Leeds."] }
let(:cont... | true |
fe3016105fa684f41697cb954a34d693a75ad9df | Ruby | mcdonaldcarolyn/ruby-collaborating-objects-lab-online-web-pt-092418 | /lib/song.rb | UTF-8 | 486 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :name, :artist
def initialize(name)
@name = name
end
def artist=(artist)
@artist = artist
end
def self.new_by_filename(filename)
new_string = filename.split(" - ")
artist_string = new_string[0]
artist_object = Artist.find_or_create_by_name(artist_string)
... | true |
50a74a70c1f3ce8f2eb31e745c8d5ffdd3d312cd | Ruby | Adam-abuba/Sparta-postcode-api-testing | /postcodes_starter_code/spec/postcode_spec.rb | UTF-8 | 6,431 | 2.65625 | 3 | [] | no_license | require 'spec_helper'
describe Postcodesio do
context 'requesting information on a single postcode works correctly' do
before(:all) do
@postcodesio = Postcodesio.new
@response = @postcodesio.get_single_postcode('SE42BE') #input a postcode
end
it "should respond with a status message of 200... | true |
42e08a5a3c785ceac3b5140e7c0175080ec5149c | Ruby | adamscottbaxter/phase-0-tracks | /ruby/vampires.rb | UTF-8 | 1,476 | 3.71875 | 4 | [] | no_license | counter = 1
puts "How many employees will be processed?"
num_employees = gets.chomp.to_i
while counter <= num_employees do
puts "What is your name?"
name = gets.chomp
puts "How old are you?"
age = gets.to_i
puts "What year were you born?"
year = gets.to_i
puts "Our company cafeteria serves gar... | true |
25466330c869d46a76541d170b7f439062f8be14 | Ruby | michballard/ruby-refresher | /lib/ruby_refresher.rb | UTF-8 | 1,987 | 3.953125 | 4 | [] | no_license | def select_elements_starting_with_a(array)
array.select { |item| item.chr == "a" }
end
def select_elements_starting_with_vowel(array)
array.select { |item| item.chr =~ /\A[aeiou]/ }
end
def remove_nils_from_array(array)
array.select { |item| item != nil }
end
def remove_nils_and_false_from_array(array)
array.s... | true |
1f5ec0ec4dc13a02aa62a733b550397303706353 | Ruby | doudou/memdump | /lib/memdump/remove_node.rb | UTF-8 | 1,226 | 2.9375 | 3 | [
"MIT"
] | permissive | module MemDump
def self.remove_node(dump, removed_node)
remaining_records = Hash.new
non_roots = Set.new
dump.each_record do |r|
address = (r['address'] || r['root'])
remaining_records[address] = r
if refs = r['references']
refs.each do |r... | true |
f251d50ce8dfdacaf650842081fcd0612cb0a0e4 | Ruby | LoadingUser3/Fall-3160 | /Labs/Lab 3/CalcRuby.rb | UTF-8 | 1,028 | 4.375 | 4 | [] | no_license | puts "Welcome to a basic Ruby Calculator!"
puts "Enter the first number"
#Initialize first number from user input
num1 = gets.to_i
puts "Enter the second number"
#Initialize second number from user input
num2 = gets.to_i
puts "Choose the operation"
puts "+ for Addition"
puts "- for Subtraction"
puts ... | true |
41abe99294b9342c781396d6dd0f0be9654dcdf7 | Ruby | lourd/6170-rush-tracker | /test/models/event_test.rb | UTF-8 | 1,358 | 2.546875 | 3 | [] | no_license | require 'test_helper'
class EventTest < ActiveSupport::TestCase
test "Check non attending rushees" do
rusheeA = rushees(:rusheeA)
rusheeB = rushees(:rusheeB)
rusheeC = rushees(:rusheeC)
eventA = events(:eventA)
eventB = events(:eventB)
eventC = events(:eventC)
fraternity = Fraternity.cr... | true |
42c933c2300af21e7591e39ba93fe206ebdb3171 | Ruby | sportymihir/FoodData | /month.rb | UTF-8 | 287 | 3.109375 | 3 | [] | no_license | class Month
attr_accessor :calories_per_day, :calorie_goal
def initialize(calories_per_day, calorie_goal)
@calories_per_day = calories_per_day
@calorie_goal = calorie_goal
end
def change_in_weight()
change = (calories_per_day - calorie_goal) * 30
change / 3500
end
end | true |
48421f94acdc0e5cd33da65c420c200c03f29476 | Ruby | koba-e964/lib-number | /alg-lin.rb | SHIFT_JIS | 1,300 | 2.8125 | 3 | [] | no_license | # coding: cp932
require 'matrix'
require_relative 'field.rb'
require_relative './gcd.rb'
def alg_as_matrix_gen(k) #basis:1,theta,...,theta^(d-1)
f=k.f
d=k.dim
ary=Array.new(d){|v|Array.new(d,0)}
for i in 0..d-2
ary[i][i+1]=1
end
denom=f[d]
raise Exception unless denom!=0
for j in 0..d-1
ary[d-1][j]=Rationa... | true |
54e00aa774fb9cd820e6152c0fc73b5efe8d0ae2 | Ruby | simcap/reviewme | /git-reviewme | UTF-8 | 3,098 | 2.875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'optparse'
# Getting main git info
current_branch = `git symbolic-ref HEAD`.chomp.split('/').last
reviewme_server_url = `git config reviewme.server.url`.chomp
publisher_email = `git config user.email`.chomp
publisher_name = `git config user.name`.chomp
# Checking correct local configuratio... | true |
b0ad4f9ab3e580c6e9c49f31a9a1ca9097795c86 | Ruby | aminbabar/w3d5 | /Knight_Travails/knight_travials.rb | UTF-8 | 1,950 | 3.734375 | 4 | [] | no_license | require "byebug"
require_relative "00_tree_node.rb"
class KnightPathFinder
def self.valid_moves(pos)
row , col = pos
moves= KnightPathFinder.permutations
valid=[]
moves.each do |move|
r = row + move[0]
c = col + move[1]
valid << [r,c] if r < 8 &&... | true |
23708025e4ae5f0f124a5880bdb2a232ac49cef3 | Ruby | rvvergara/data-structures | /tree_height.rb | UTF-8 | 1,790 | 3.453125 | 3 | [] | no_license | # RyanV solution
require 'benchmark'
# node height = 1 + max(left height, right height)
def do_stuff(arr)
#0 Declare heights array that will store the heights of individual subtree (node)
heights = []
#1 Iterate through the input array starting from last element down to first
(arr.size - 1).downto(0) do |i|
#... | true |
419ff244da6b458a0d21c19fde4b445bc494eb39 | Ruby | mobalean/rubyeigo | /17_proc_bind_test.rb | UTF-8 | 469 | 3.15625 | 3 | [] | no_license | require 'test/unit'
class Proc
def bind(object)
end
end
class ProcTests < Test::Unit::TestCase
class Example
def initialize
@i = 1
end
end
def test_bind_returns_method_with_changed_self
block = Proc.new { self }
assert_equal self, block.call
bound_block = block.bind("hello")
ass... | true |
55622e8ef2c64d173e898d8db10accecc2110ebd | Ruby | Ichenn92/mastermind | /master-mind.rb | UTF-8 | 675 | 2.796875 | 3 | [] | no_license | require 'bundler/inline'
gemfile true do
source 'http://rubygems.org'
gem 'colorize'
gem 'io-console'
end
require 'colorize' # for repl.it add the gem
require 'io/console'
require_relative './class/color'
require_relative './class/game'
require_relative './class/player'
require_relative './class/rules'
require_rel... | true |
955220f75f1196bcabf162084f41ebc1f287d6c5 | Ruby | gropax/gramz | /lib/gramz/cfg/rule/alternative.rb | UTF-8 | 373 | 2.90625 | 3 | [
"MIT"
] | permissive | module Gramz
module CFG
class Rule
class Alternative
attr_reader :left_symbol
def initialize(lsym, alts)
@left_symbol = lsym
@ary = alts
end
def [](i)
@ary[i]
end
include Enumerable
def each(&blk)
@ary.each { |... | true |
f9d75a3c080815f81eb6787eeaa329e3fd059c28 | Ruby | sato0208/Ruby_lesson | /lesson5/lesson5_7_3.rb | UTF-8 | 702 | 3.953125 | 4 | [] | no_license | # シンボルと文字列の関係性
string = 'apple'
symbol = :apple
string == symbol
string + symbol
# 文字列をシンボルに変換
string = 'apple'
symbol = :apple
string.to_sym
string.to_sym == symbol
# シンボルを文字列に変換
string = 'apple'
symbol = :apple
symbol.to_s
string == symbol.to_s
string + symbol.to_s
# respond_to? メソッドの引数には文字列とシンボルの両方を渡せる
'appl... | true |
9666b9a5ee2a517808bd3f7eb46dbcaa22a73e7f | Ruby | rina2803/devoir_rina | /POO/pro/app.rb | UTF-8 | 339 | 2.671875 | 3 | [] | no_license | require 'bundler'
Bundler.require
require_relative 'lib/user'
require_relative 'lib/event'
julie = User.new("julie@email.com", 35) #je crée un premier User
jean = User.new("jean@maimail.com", 22) #puis un second User
my_event = Event.new("2019-01-13 09:00", 10, "standup quotidien", [julie, jean]) #et je les insère t... | true |
2d2442e2ae92a95629e3d7b23b3d999a817c977e | Ruby | nicoolas25/geocoin | /lib/geocoin/search_result.rb | UTF-8 | 562 | 2.671875 | 3 | [] | no_license | module Geocoin
class SearchResult
attr_reader :url, :label, :price, :date, :city, :img, :lat, :lng, :location
def initialize(attrs = {})
attrs.each { |name, value| instance_variable_set("@#{name}", value) }
end
def set_coordinates(locator)
@lat, @lng, @location = locator.coords(city.firs... | true |
6714f57898a3a374b413bb70d85f6d2d039ca518 | Ruby | open-telemetry/opentelemetry-ruby | /api/lib/opentelemetry/baggage.rb | UTF-8 | 3,607 | 2.765625 | 3 | [
"Apache-2.0",
"Ruby",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
require 'opentelemetry/baggage/propagation'
require 'opentelemetry/baggage/builder'
require 'opentelemetry/baggage/entry'
module OpenTelemetry
# The Baggage module provides functionality to record and propag... | true |
49510df03f9bb610851099c6492af69a12fdec83 | Ruby | steezy2/AlgoBowl | /Algobowl.rb | UTF-8 | 1,263 | 3.515625 | 4 | [] | no_license | def create_input(n)
outputarr = []
max = rand(1000)
value = 2
for i in 1..n do
max = rand(7000000)
value = rand(value..max+value)
line = "#{value}"
outputarr << line
end
outputarr
end
def verfier(filename)
file_data = File.read(filename).split("\n")
n = file_data[0]
validnums = [1]
... | true |
b6c353ba34ba70dd571b1d583b795833fdf2740c | Ruby | rCamposCruz/gympass | /gympass/lib/gympass/piloto.rb | UTF-8 | 1,265 | 3.34375 | 3 | [
"MIT"
] | permissive | class Piloto
attr_accessor :laps, :name
def initialize(name)
@name = name
@laps = []
@avg_speeds = []
end
def to_s
[@name, "TOTAL TIME: #{total_time}", "MEDIAN SPEED: #{avg_speed}"].to_s
end
def valid?
@name.size > 0
end
def load_lap(lap_n, lap_time, avg_speed)
@laps << [lap_n, lap_time]
@avg_... | true |
10f990c187e9757fbf3f43c8e4b887122bbcdf45 | Ruby | Aphilosopher30/whats-in-my-food-2103 | /spec/features/poros/food_spec.rb | UTF-8 | 586 | 2.65625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Food do
describe "food class exists with atributes" do
it "has atributes" do
info = {description: "orang tea",
brand: "bigalo",
gtinUpc: "bla bla blaa",
ingredients: "oranges and tea leaves"
}
food = Food... | true |
3530068cdcf31c5efbe6253981287a89adc94859 | Ruby | codetangle/ruby-poker-game-exercise | /Table.rb | UTF-8 | 1,549 | 4.09375 | 4 | [
"MIT"
] | permissive | require './Player.rb'
require './Game.rb'
class Table
def initialize(seats)
i = 0
@players = []
while i < seats
@players.push(Player.new())
i += 1
end
@dealer_button = rand(0...seats)
@game = "Texas Hold'em"
end
def display_players()
puts "Current Players"
@players.each do |val|
puts val... | true |
c4e469f9910ec9aee1574830b32bc92a9817df63 | Ruby | t33chong/lita-forecast | /spec/lita/handlers/forecast/location_spec.rb | UTF-8 | 6,035 | 2.671875 | 3 | [
"MIT"
] | permissive | # -*- coding: UTF-8 -*-
require 'spec_helper'
require 'hashie'
# Class for stubbing Geolocation data
#
class MockGeocoderClass
DATA = {
'address_components' => [
{ 'long_name' => 'San Francisco', 'types' => %w(locality) },
{ 'short_name' => 'CA', 'types' => %w(administrative_area_level_1) }
],
... | true |
90505cb5c902bb9920dbb4a24100e1f746f4fe9a | Ruby | kwmcminn/prime-ruby-seattle-web-career-012819 | /prime.rb | UTF-8 | 231 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime? (n)
if n < 2
return false
elsif n == 3
return true
end
array = []
for i in (2..(n/2)) do
array.push(i)
end
array.each do |i|
if n % i == 0
return false
end
end
return true
end
| true |
c1626864be5298b316264fa60efe5c9b5e74ab14 | Ruby | willfowls/launchschool | /rb_101/small_problems_exercises/easy_6/delete_vowels.rb | UTF-8 | 190 | 3.53125 | 4 | [] | no_license | # Write method taking arary of strings
# Return array of same string vals with vowels removed
def remove_vowels(arr)
n = []
arr.each do |v|
n << v.delete('aeiouAEIOU')
end
n
end | true |
c90c991d1a83fb5f6133ab2512661c49c53d6c34 | Ruby | dalspok/intro_to_prog | /loops/loops_3.rb | UTF-8 | 80 | 3.171875 | 3 | [] | no_license | array = [1, "ahoj", 4, "b"]
array.each_with_index {|val, i| puts "#{i}:#{val}"} | true |
04b9918c8dc201556120281d51a50f453b74b76d | Ruby | volpja46/anagram-detector-web-071717 | /lib/anagram.rb | UTF-8 | 448 | 3.296875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Anagram
attr_accessor :name
def initialize(word)
@name = word
end
def match(array)
array.select {|word| word.split("").sort == @name.split("").sort}
end
# splits on each letter!! word.split. sort (will account for dif arrangement of lettters
# split on each letter of the name )
# takes ... | true |
af911993e1ecd732969001b4f745a0b9c0975aac | Ruby | martinpoljak/unified-queues | /lib/unified-queues/multi/driver/unified-queues.rb | UTF-8 | 7,427 | 3.046875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # encoding: utf-8
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
require "hash-utils/array"
require "hash-utils/object"
##
# Base +Unified Queues+ module.
#
module UnifiedQueues
##
# Universal multi queue interface.
#
class Multi
##
# Abstract multi driver class.... | true |
a83f9556cde269d1607223dd1d751c20c13a067e | Ruby | codeunion/codeunion-client | /lib/codeunion/search.rb | UTF-8 | 1,147 | 2.96875 | 3 | [
"MIT"
] | permissive | require "rainbow"
require "codeunion/helpers/text"
module CodeUnion
class Search
# Prepares a search result for presentation in the CLI
class ResultPresenter
include CodeUnion::Helpers::Text
EXCERPT_REGEX = /<match>([^<]*)<\/match>/
def initialize(result)
@result = result
end... | true |
77c04c8182823c1fb049b7b83c5fa29b516b5925 | Ruby | honjintang/student-directory | /ex14/Ex14.8.rb | UTF-8 | 132 | 2.84375 | 3 | [] | no_license | #Write a short program that reads its own source code and prints it on the screen.
File.open(__FILE__, "r") {|file| puts file.read}
| true |
234f0b41b775e9214ea54e291132c10c5fd8bb34 | Ruby | SAHAMOLI/BNSDemo | /features/Utilities/Expectations/expectations.rb | UTF-8 | 1,337 | 2.96875 | 3 | [] | no_license | def verify_text(element, expected_text)
locator = find_locator(element)
$browser.element(:xpath => locator).scroll_into_view
actual_text = $browser.element(:xpath => locator).wait_until(&:present?)
fail "Failed comparison for the #{element} element:\n\tExpected: #{expected_text}\n\tActual: #{actual_text}"
end... | true |
21dfdd10be109d6ba3ab6820f661ac8f0519db8e | Ruby | Felipeandres11/rfm | /lib/rfm/utilities/scope.rb | UTF-8 | 3,669 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'rfm'
require 'rfm/base'
module Rfm
module Scope
SCOPE = Proc.new {[]}
# Add scoping to Rfm::Base class methods for querying fmp records.
# Usage:
# class MyModel < Rfm::Base
# SCOPE = proc { |optional-scope-args| <single-or-array-of-fmp-request-hashes> }
# end
#
# O... | true |
c348d6c04e830f5c0914edb85521f0ed212b4804 | Ruby | Kira-kyuukyoku/kata | /fibonacci/fibograph.rb | UTF-8 | 645 | 4 | 4 | [] | no_license | def fibo(chiffre)
a = 1
b = 1
c = 0
i = 0
j = 0
result = []
string = "|"
while i <= chiffre do
a = b
b = c
c = a + b
result << string * c
i += 1
end
result
end
print "Entrez un chiffre: "
# Converti le ... | true |
125a6022ed4d6457728a6d4ea91695a1fde4c873 | Ruby | marcusshepp/CardistryIO | /app/helpers/current_path_helper.rb | UTF-8 | 512 | 2.53125 | 3 | [] | no_license | module CurrentPathHelper
def current_path_class(path)
current_route = Rails.application.routes.recognize_path(path)
if should_be_highlighted?(path, current_route)
"active-nav-item"
end
end
private
def should_be_highlighted?(path, current_route)
current_page?(path) || controller_action_ma... | true |
529be0e7a1191e197545a4dee1952f34a73a96c0 | Ruby | awasthi/maildis | /lib/maildis/recipient_parser.rb | UTF-8 | 2,305 | 2.890625 | 3 | [
"MIT"
] | permissive | require_relative 'validation_error'
require_relative 'recipient'
require 'csv'
module Maildis
class RecipientParser
class << self
@@expected_columns = [:name, :email]
def valid_csv?(file_path)
csv = extract_data file_path
begin
validate_headers(normalize_headers(csv.head... | true |
55764a966152aae5a037e5a0619473d306e85245 | Ruby | hitherjarl/2 | /9.rb | UTF-8 | 142 | 3.328125 | 3 | [] | no_license | def say_moo number_of_moos
puts 'mooooooo...'*number_of_moos
'yellow submarine'
end
x = say_moo 3
puts x.capitalize + ', dude...'
puts x + '.' | true |
001bcdb546dfd1914cc90c6062a4ff54e85d2d52 | Ruby | dvdpostweb/moovies | /config/initializers/date_time_formats.rb | UTF-8 | 740 | 2.90625 | 3 | [] | no_license |
Time::DATE_FORMATS[:datetime] = "%H:%M %d-%b-%Y" # date.to_s(:datetime) ----> 15:30 24-Dec-2009
Time::DATE_FORMATS[:date] = "%d/%b/%Y" # date.to_s(:date) ----> 24-Dec-2009
Time::DATE_FORMATS[:time] = "%H:%M" # date.to_s(:time) ----> 15:30
Time::DATE_FORMATS[:google] = "%Y-%m-%d ... | true |
ca447bf8205a730e3a5e283ad1108ba27a57e906 | Ruby | MBennettLowe/RoR-Prepwork | /arrays_ex7.rb | UTF-8 | 456 | 4.4375 | 4 | [] | no_license | #7.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 instea... | true |
69ffd6807a94b350b3393461bca55beb636efaa3 | Ruby | ninjaofawesome/project_folder | /self_imposed_challenges/tests/hannah.rb | UTF-8 | 225 | 3.34375 | 3 | [] | no_license |
# def names
# ["hannah", "rupert", "jennifer"].each do |name|
# puts (name + " ") * 3
# end
# end
def numbers
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each do |print|
puts "This rad number is #{print}"
end
end
numbers
| true |
3a8128d83339d6aa1d91cc80aeff85a43634ac4a | Ruby | mannyng/shoepy | /app/models/cart.rb | UTF-8 | 420 | 2.640625 | 3 | [] | no_license | class Cart < ApplicationRecord
has_many :line_items, dependent: :destroy
def add_product(product_id,user_id)
current_item = line_items.find_by(product_id: product_id)
if current_item
current_item.quantity += 1
else
current_item = line_items.build(product_id: product_id,user_id: user_id)
end
cu... | true |
249f97acf2e0844d5214ec6bb903f2167ab9067c | Ruby | bsgreenb/programming-challenges | /1_arrays_and_strings/1_1_is_unique.rb | UTF-8 | 609 | 4.40625 | 4 | [] | no_license | # Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
# My approach will be to sort then check for duplicates. this doesn't require a data structure for storage.
# If we were using a data structure, we could could have an ASCII array or bools,... | true |
0d3ceec639ed8a5c8cc6c4c5c452218c6526e443 | Ruby | garethlatwork/quickbase_client_extras | /lib/QuickBaseTextData.rb | UTF-8 | 22,169 | 2.75 | 3 | [] | no_license | #--#####################################################################
# Copyright (c) 2009-2011 Gareth Lewis and Intuit, Inc.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is... | true |
f8cf93ec9d25d1d8b56deed57e3e4274d43ca264 | Ruby | POgawa/learnstreet | /Calculator/calculator-ruby.rb | UTF-8 | 379 | 3.3125 | 3 | [] | no_license | #Basic calculator project
include Math
def cube(n)
@cube=n*n*n
end
def squareroot(n)
if n < 0 then
return "NAN"
else
return Math.sqrt(n)
end
end
def negate(n)
return -n
end
def factorial(n)
if n ==0 then
return 1
end
if n < 0 then
... | true |
9876aacd9fd4f0139de23b46642785e2e25ea003 | Ruby | atomicobject/piece_pipe | /spec/assembly_step_spec.rb | UTF-8 | 4,401 | 2.859375 | 3 | [
"MIT"
] | permissive | require "spec_helper"
describe PiecePipe::AssemblyStep do
context "default AssemblyStep" do
it "produces unaltered items from its source" do
as = PiecePipe::AssemblyStep.new
as.source = [
{hello: "hippo"},
{hello: "lion"}
]
as.to_enum.to_a.should == [
{hello: "hip... | true |
4b7a88a1867386f10cbe0992543bfc7370f7b349 | Ruby | NivxB/PlanificadorRutas | /graph.rb | UTF-8 | 472 | 3.5 | 4 | [] | no_license | class Graph
attr_reader :nodes
def initialize
@nodes = {}
end
def add_node(node)
@nodes[node.name] = node
end
def add_edge(predecessor_name, successor_name,weight)
@nodes[predecessor_name].add_edge(@nodes[successor_name],weight)
end
def get_node(nodeName)
return @nodes[nodeName]
e... | true |
3aff83893d50a71d6f651a13a068a6bbf29ab1a5 | Ruby | gulazaro94/lol_champions | /services/data_filtering.rb | UTF-8 | 1,032 | 2.734375 | 3 | [] | no_license | module Services
class DataFiltering
def initialize(champions_data, items_data)
@champions_data = champions_data
@items_data = items_data
end
def filter
@champions_data['data'].map do |champion_key, champion_data|
{id: champion_data['id'], key: champion_key, name: champion_data[... | true |
f06c89277c32d77a41d5c1f01bdbf1acb4c33b24 | Ruby | bu6hunt3r/myown | /f4ncy_stuff/host_patcher.rb | UTF-8 | 949 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
#coding: utf-8
require 'optparse'
options={}
ARGV << "-h" if ARGV.empty?
parser=OptionParser.new {|opts|
opts.banner="Usage: $0 [-l|-r]"
opts.on("-l", "--localhost", "Patch to localhost") do |l|
options[:localhost]=true
end
opts.on("-r", "--remote", "Patch to remote host") do |r|
options... | true |
da2937b195a4efc360f4487317c7161dc8cd8640 | Ruby | sfahado/CodilityInRuby | /libs/dynamicprogramming/number_solitaire.rb | UTF-8 | 2,471 | 3.625 | 4 | [
"MIT"
] | permissive | # This is the solution for Dynamic programming > NumberSolitaire
#
# This is marked as RESPECTABLE difficulty
# Note here we have the evolution of the algorithm. Only the last class is the correct one.
class NumberSolitaireRecursive
def solution(a)
max_sum_six_distances(a, 0)
end
def max_sum_six_distances(a... | true |
c6ac43e407db81ae11875b7b63bf8008985b5fef | Ruby | bitzesty/qae | /app/services/utils/diff.rb | UTF-8 | 275 | 2.640625 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
module Utils
class Diff
def self.calc(v1, v2, abs: true)
return nil unless ::Utils::String.integer?(v1) && ::Utils::String.integer?(v2)
res = v1.to_i - v2.to_i
abs ? res.abs : res
rescue
nil
end
end
end
| true |
6db20580499dc0054752baf1e0ab52a45e3956f5 | Ruby | hoopla-software/hoopla-force-connector | /lib/hoopla_force_connector/sanitizer.rb | UTF-8 | 1,869 | 2.703125 | 3 | [] | no_license | class HooplaForceConnector
# Handles sanitization of values that come out of the salesforce WebServices API.
# Basically there's some oddities like extra wrappers on a return value or ids
# coming through as arrays. See the test for examples of what this handles.
class Sanitizer
def self.sanitize(raw)
... | true |
77f6be114288f8aac5161a77ff8c8fb6536bd591 | Ruby | kputnam/detritus | /ruby/nl/time/durations/compound.rb | UTF-8 | 674 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
# $Hg: compound.rb 57ae291ab1d4 2008-01-05 17:41 -0600 kputnam $
module NLTime
class Duration::Compound < Duration
def initialize(*args)
@args = args
end
# simplify like 90 minutes => 1 hour 30 minutes
def normalize
end
# return compatible forms of self and other
def coerce... | true |
e2fc1b93175383ef16f35799a6a10a75e776e7b0 | Ruby | sgrant0225/ruby-object-attributes-lab-onl01-seng-pt-021020 | /lib/person.rb | UTF-8 | 186 | 2.859375 | 3 | [] | no_license | class Person
def name=(name_of_person)
@name = name_of_person
end
def name
@name
end
end
class Person
def job=(person_job)
@job = person_job
end
def job
@job
end
end | true |
36d57eae8058975dce320562e66029eeb10a3a22 | Ruby | mariomanzoni/Enterprise-Recipes-with-Ruby-and-Rails | /code/testing/rspec/rspecmocks/vendor/plugins/rspec/stories/stories/steps/multiline_steps.rb | UTF-8 | 699 | 2.59375 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Enterprise Recipes for Ruby and Rails",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose... | true |
e55fab933b99e7912d10d3649963aaa4d8158fc6 | Ruby | SammySteiner/dot-align-sql | /lib/sql_query_two.rb | UTF-8 | 323 | 2.78125 | 3 | [] | no_license | require 'sqlite3'
db = SQLite3::Database.open('db/Data.db')
emails = db.execute("SELECT email_address.address_text, person.name FROM email_address JOIN person ON email_address.person_id == person.id;")
puts 'address_text | name'
puts "--------------------------"
emails.each do |e|
puts e[0] + ' | ' + e[1]
e... | true |
634242ac8175634feea2c04edb689c1852fab7f4 | Ruby | shreve/omnibar | /lib/omnibar/queries/github.rb | UTF-8 | 675 | 2.578125 | 3 | [
"MIT"
] | permissive | module Omnibar
class Github < Query
def result
repo = search.find(input)
return repo if repo
return input if repo_full_name?
end
def self.search
@fm ||= FuzzyMatch.new(Omnibar.config.github.repos)
end
def perform!
param = result.downcase.gsub(/\s/, '-')
open_i... | true |
a5859309bb0059d5f453498a919f5c6e5c9d4bde | Ruby | ericallfesta/kirarirenew | /proto.git 2/app/models/search_keyword.rb | UTF-8 | 542 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | class SearchKeyword
class << self
def instance
@instance ||= SearchKeyword.new
end
def list_name date = nil
date = Date.today if date.nil?
"search:keywords:#{date.strftime("%Y%m%d")}"
end
end
def push args = {}
redis.lpush( self.class.list_name, args[:face] )
end
def r... | true |
8fa05944fb9849d77e4fe8cecb58368cf28e8580 | Ruby | d-otis/oo-cash-register-onl01-seng-pt-012120 | /lib/cash_register.rb | UTF-8 | 836 | 3.296875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class CashRegister
attr_accessor :total, :discount, :items, :last_item
def initialize(discount = 0)
@total = 0
@discount = discount
@items = []
end
def add_item(title, price, quantity = 1)
@total += price * quantity
quantity.times do
@items << title
end
... | true |
e997c9810f7d0c7e0b4811474afc26fbe8637f29 | Ruby | contact411/WDI_SYD_7_NEW | /joel/wk9/d03/warmup/cards.rb | UTF-8 | 1,576 | 4.3125 | 4 | [] | no_license | class Card
attr_reader :val, :suit
def initialize(val, suit)
@val = val
@suit = suit
end
def to_s
@val.to_s + ' of ' + @suit + 's'
end
end
class Deck
attr_reader :cards
def initialize
@cards = []
values = ['Ace', (2..10).to_a, 'Jk', 'Qn', 'Kg'].flatten
suits = ['spade', 'h... | true |
8b61f98ebab03d44b3dbd5e980e481443e4ee186 | Ruby | wetwicky/SVar | /spec/spec_helper.rb | UTF-8 | 1,094 | 2.8125 | 3 | [
"MIT"
] | permissive | gem 'minitest'
require 'minitest/autorun'
require 'minitest/spec'
Thread.abort_on_exception = true
class Object
#
# Permet de sauter une suite de tests.
#
def _describe( test )
puts "--- On saute les tests pour \"#{test}\" ---"
end
#
# Permet de sauter un test.
#
def _it( test )
puts "--- O... | true |
9ec9ae7369b323f7249ce092eb1648f3655af7cd | Ruby | JCGuest/ruby-objects-has-many-lab-online-web-pt-081219 | /lib/author.rb | UTF-8 | 312 | 3.21875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Author
attr_accessor :name
def initialize(name)
@name = name
end
def posts
Post.all
end
def add_post(post)
post.author = self
end
def add_post_by_title(title)
title = Post.new(title)
title.author = self
end
def self.post_count
Post.all.count
end
end | true |
5ad9fbcf2590da51d30c8ae72c53b45fed6fedd4 | Ruby | qw3/getnet_api | /lib/getnet_api/credit.rb | UTF-8 | 3,100 | 2.625 | 3 | [
"MIT"
] | permissive | # -*- encoding : utf-8 -*-
module GetnetApi
class Credit < Base
# Boolean Required
# Identifica se o crédito será feito com confirmação tardia.
attr_accessor :delayed
# Boolean
# Indicativo se transação deve ter o processo de autenticação no emissor, caso authenticated = true, o portador deve se... | true |
a2822418e3afe436e18d949601f95c53fc9b87b3 | Ruby | CEAHMAD/blogy | /app/models/car.rb | UTF-8 | 280 | 2.515625 | 3 | [] | no_license | class Car < ApplicationRecord
validates :make, presence: true
validates :model, presence: true
validates :color, presence: true
validates :year, length: {
maximum: 4,
minimum: 4,
too_short: "must have at maximum %{count} digits"
}
end
| true |
0f68f6d4759a7e910c07eaa2a93bf3974b7d799c | Ruby | RoseliLopes/Ruby-class | /12_hashes.rb | UTF-8 | 731 | 3.78125 | 4 | [] | no_license | # 1 -> Introdução
{}
{'nome' => 'Anderson', 'sobrenome' => 'Dias'}
{:nome => 'Anderson', 'nome' => 'Dias'}
# 2 -> Acessando elementos de um hash
dados = {'nome' => 'Anderson', 'sobrenome' => 'Dias'}
puts dados
puts dados['nome']
puts dados['idade']
dados['idade'] = 24 # Sem brincadeiras, por favor...
puts dados['ida... | true |
574a5a580ffdcd7521fa2c55954e46921b0f4be8 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/b5985e1a4896414abf4a8e1f54b0cecb.rb | UTF-8 | 521 | 3.546875 | 4 | [] | no_license | class Phrase
attr_reader :word_count
def initialize(words)
count(words)
end
private
def count(words)
words_array = find_all_words(words)
count_each_word(words_array)
end
def find_all_words(words)
words.downcase.scan(/\w+/)
end
def count_each_word(words_array)
... | true |
b7e02076458829e1a30a9e8713e6d5345eab0fe6 | Ruby | tschaffer1618/module_0_capstone | /day_2/array_practice.rb | UTF-8 | 1,247 | 4.25 | 4 | [] | no_license | # double the numbers in the array
a = [1, 2, 3, 4]
a.each do |x|
puts x * 2
end
# triple the numbers in the array
a.each do |x|
puts x * 3
end
# print the even numbers
a.each do |x|
puts x if x % 2 == 0
end
# print the odd number
a.each do |x|
puts x if x % 2 == 1
end
# create a new array with double the nu... | true |
8ca9d322a2e4fc991a446419803c8bb3345df405 | Ruby | biud436/RGSS3 | /RS_SimpleMapEditor.rb | UTF-8 | 12,833 | 2.890625 | 3 | [
"MIT"
] | permissive | #================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
# ===========================... | true |
94cc580eaf00ab19c0c5b65ea9817b0d73abe421 | Ruby | svbarilov/ruby_kick_prologs_ass | /test/lists_test/test_23.rb | UTF-8 | 340 | 2.78125 | 3 | [] | no_license | require 'test_helper'
require 'lists/23'
class Problem23Test < Test::Unit::TestCase
context "a problem 23 " do
setup do
@list = [1,2,3,4,5]
end
should "extract a given number of randomly selected elements from a list" do
assert_equal true, Problems::List.rnd_select(@list, 3).is_a?(Array... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.