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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6e3fc2ea255f48950e0b6b05ceb8ddaf1301ad04 | Ruby | ktaragorn/mobile_detect | /lib/mobile_detect/core.rb | UTF-8 | 4,898 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'json'
class MobileDetect
attr_reader :http_headers
attr_writer :user_agent
# Construct an instance of this class.
# @param [hash] http_headers Specify the http headers of the request.
# @param [string] user_agent Specify the User-Agent header. If null, will use HTTP_USER_AGENT
# ... | true |
a5cd271abb67639f7288c1cef97f0f9fba3c6f8e | Ruby | Liboul/martyr | /spec/helpers/intervals_spec.rb | UTF-8 | 25,580 | 2.75 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
def define_date_functions
[0, 1, 2, 5, 10, 15, 20, 25, 30, 40, 45, 50, 80, 90, 100, 101, 150, 200, 250, 300, 350, 400, 500, 600].each do |x|
let("d#{x}") { x.days.from_now }
end
end
describe Martyr::Interval do
define_date_functions
describe 'initialize' do
it 'does not allow fr... | true |
3ea059534f4324894de5f975c7fa3473476603b1 | Ruby | sergiovasquez122/Programming-Languages-Coursera-Solutions | /week8/introduction_to_ruby.rb | UTF-8 | 588 | 3.78125 | 4 | [] | no_license | # Pure object-oriented: all values are objects
# Class-based: Every object has a class that determines behavior
# - Like Java, unlike Javascript
# - Mixins
# Dynamically typed
# Convenient reflection: Run-time inspection of objects
# Very dynamic: Can change class during execution
# Blocks and libaries encourages lots ... | true |
360637bae4d556bcf1892011fc30f3c3c585b60d | Ruby | laneb/classical_crypto | /lib/classical_crypto/cyphers/playfair.rb | UTF-8 | 1,797 | 3.34375 | 3 | [] | no_license | require_relative "../utils.rb"
require_relative "./cypher.rb"
module ClassicalCrypto::Cyphers
class Playfair < Cypher
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~Class: Playfair
#
#~~Description: Playfair is a subclass of Cypher which encrypts alphanumeric text
... | true |
9dd6f6e75bf4ffb62f6892fe50f3c3b3b33a9477 | Ruby | htachib/clerk | /lib/google_sheets.rb | UTF-8 | 2,498 | 2.671875 | 3 | [] | no_license | class GoogleSheets
require 'google/apis/sheets_v4'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'fileutils'
APPLICATION_NAME = 'Google Sheets API Ruby Quickstart'.freeze
OOB_URI = 'https://f256f093.ngrok.io/oauth2callback'
# The file token.yaml stores the user's access and re... | true |
dacb5891fe6ec0c1d34da48cc65a7bf29f277e76 | Ruby | bmoises/project-euler | /lib/fibonacci.rb | UTF-8 | 504 | 3.671875 | 4 | [] | no_license | class Fibonacci
attr_accessor :continue, :current, :n1, :n2
def initialize
@continue = true
@current, @n1, @n2 = 0, 0, 0
end
def each
while true
break if !@continue
if @current >= 2
@current = @n2 + n1
@n1 = @n2
@n2 = @current
elsif @current == 0
... | true |
e4af222975b9a06c3ff812602400c07632fb9165 | Ruby | mstolbov/rocket_model | /lib/rocket_model/store/file.rb | UTF-8 | 1,479 | 2.71875 | 3 | [
"MIT"
] | permissive | require "pstore"
module RocketModel
module Store
class File < PStore
def self.new(path:)
super(path)
end
def initialize(path)
super
@table = {}
fetch_all
end
def all(table:)
@table[table] || []
end
def create(data, table:)
... | true |
8a5a926e838cc18221ec912519a181eaa01939eb | Ruby | jfdimark/lesson02 | /arrays.rb | UTF-8 | 517 | 4.5 | 4 | [] | no_license | # 1. create an array with three different string values
three_amigos = ["John", "Tom", "Bob"]
# 2. add two new values to the Task #1 array in single expression
puts three_amigos.unshift("Jason", "Jim")
# 3. convert your name to an array, and display it, in a single expression
puts ["Mark", "Walker"]
#... | true |
e87fea7eae732ac31b2bbce7487d894ca6f56a5f | Ruby | eatoncns/ttt_web | /lib/game_mode.rb | UTF-8 | 878 | 3.3125 | 3 | [] | no_license | require 'ttt_core'
require_relative 'web_player'
class GameMode
Computer = TttCore::Computer
Human = WebPlayer
attr_reader :player_one_type
attr_reader :player_two_type
attr_reader :board_dimension
def initialize(params)
board_dimension = params["board_dimension"].to_i
@board_dimension = board_... | true |
36f676b1ef5f213271991c5065b6a8cde98df2dd | Ruby | hajoxx/simple-cdn-server | /lib/simple_cdn/server/ftp/driver.rb | UTF-8 | 1,866 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'fileutils'
module SimpleCDN
class Server::Ftp::Driver
# Your driver's initialize method can be anything you need. Ftpd
# does not create an instance of your driver.
def initialize(base_dir)
@base_dir = base_dir
@access_dir = '/dev/null'
end
# Return true if the user shou... | true |
58f7f51c3bc322d69ff52feef5c6be378b4183b6 | Ruby | bryanduxbury/indicatinator | /crossover.rb | UTF-8 | 3,395 | 3.203125 | 3 | [] | no_license | # scheme = [5, 4, 1, 0, 3, 2]
require "rubygems"
require "ruby-debug"
schemes = []
def populate_schemes(alphabet, so_far, results, depth=0)
if alphabet.empty?
results << so_far
return
end
for a in alphabet
# this heuristic allows us to be sure we're never generating a pass-through
# transposition... | true |
eb973f50f48366ba9773e436d40bfd766b6e73a2 | Ruby | WWCodeMID/ruby-taller | /metodos.rb | UTF-8 | 732 | 4.34375 | 4 | [] | no_license | # Las funciones o métodos son bloques de código
# Reutilizables. Pueden o no recibir parámetros.
def hello
print "Hello"
end
# Se pueden especificar parámetros opcionales.
def hello_name(name = "You")
print "Hello #{name}!"
end
# Los métodos tambien pueden procesar y
# regresar valores o cadenas.
def return_hell... | true |
810b9ff8ad71c23b1a51eb67663b52bc4b7cf46b | Ruby | Anna-Myzukina/Algorithms-Data-Structures | /Sets.rb | UTF-8 | 1,464 | 4.53125 | 5 | [] | no_license | =begin
Sets
These are the important methods a Set supports:
add(item) - Adds an item to the Set.
delete(item) - Removes an item from the Set.
include?(item) - Returns true if the item is in the Set, and false otherwise.
Purpose of Sets
The Set is useful when you want to check if items are in a collection but there's ... | true |
9c682d82998e7d64ba26dfa24c726244218d1fb0 | Ruby | maxmartinm/Max.Martin.maxmartinm | /d2/bouncer.rb | UTF-8 | 199 | 3.953125 | 4 | [] | no_license | puts "Hello!"
puts "What's your age?"
age = gets.strip.to_i
if age >= 50
puts "You're too old"
elsif age >= 21
puts "You're old enough! Come on in!"
else
puts "Sorry. You're too young."
end
| true |
a8d88e29fb5df4271f1d46e30bb2dfe9fada8343 | Ruby | oleglr/forecast | /senti/topic3/news_bow3.rb | UTF-8 | 3,980 | 2.515625 | 3 | [] | no_license | #!/bin/env ruby
# coding:utf-8
require "natto"
require "json"
require "sqlite3"
class MakeBOW
def initialize
@dr="../../../data/data/news"
#@docs=Hash.new # key:doc, value:vector ,word count
#@keys=Hash.new # key:word , value:docs vector index
@natto = Natto::MeCab.new
@files=[]
@db=SQL... | true |
82c1bc81783a7903da3b3b66356b350f237bd5d6 | Ruby | todb-r7/junkdrawer | /wallet-info.rb | UTF-8 | 698 | 2.859375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Just goofing around with simplistic data gathering given a BitCoin
# wallet...
module BitCoin
class Wallet
ADDRESS_REGEX = /\x04name\x22[13][A-Za-z0-9]{26,33}/
attr_reader :addresses
def initialize(fname="./wallet.dat")
@data = File.open(fname, "rb") {|f| f.read f.stat.siz... | true |
55a0851c58f5faff31edcad3b09a8b3278b92703 | Ruby | uchennafokoye/ruby_algorithms | /lib/ruby_algorithms/graph_algorithms/dfs.rb | UTF-8 | 1,494 | 3.203125 | 3 | [
"MIT"
] | permissive | module GraphAlgorithms
class DFS
def initialize graph, start
validate_graph graph
validate_vertex_exists graph, start
dfs(graph, start)
end
def path_to v
recursive_path_to v
end
private
attr_reader :state, :discovered, :finished, :parent, :counter
# Also repeate... | true |
173aa849bb4c581a60264ab9346f8d3d0f115831 | Ruby | breycarr/poker_scoring | /spec/card_spec.rb | UTF-8 | 415 | 2.71875 | 3 | [] | no_license | require 'card'
describe Card do
let(:subject) { Card.new("2S") }
it "has a suit" do
expect(subject.suit).to eq("S")
end
it "has a rank" do
expect(subject.rank).to eq("2")
end
it "can treat the rank as a value" do
expect(subject.value).to eq(2)
end
it "can ... | true |
944eb07aba4c616e6feb834bb6a3bba54b4d44b7 | Ruby | katebee/gems-and-snakes | /spec/fruit_machine_spec.rb | UTF-8 | 2,974 | 3.4375 | 3 | [] | no_license |
require_relative '../fruit-machine/fruit_machine'
require 'rspec'
describe Player do
it 'should initialize' do
player = Player.new(100)
expect(player.wallet_fund).to eq 100
expect(player.play_credit).to eq 0
end
end
describe Machine do
it 'should initialize' do
machine = Machine.new(2222, 50)
... | true |
0e574519444f36e6b36a2cfe80bd34d76bbda5e5 | Ruby | thejapanexperience/code-wars-ruby | /7kyuBeginnerSeries#3SumOfNumbers.rb | UTF-8 | 199 | 3.4375 | 3 | [] | no_license | def get_sum(_a, _b)
return _a unless _a != _b
ans = 0
if _a < _b
(_a.._b).each { |num| ans += num }
else
(_b.._a).each { |num| ans += num }
end
puts ans
ans
end
get_sum(5, -1)
| true |
524b470eabb8d8e221b730c996f2b1c193d73eee | Ruby | geelen/box | /app/definitions.rb | UTF-8 | 1,255 | 2.546875 | 3 | [] | no_license | require "rubygems"
require "term/ansicolor"
include Term::ANSIColor
$command_line_options = Hash[*ENV.keys.grep(/^with_(.+)/) { |param| [$1.to_sym,ENV[param]] }.flatten]
$working_dir = $command_line_options[:dir] || Dir.pwd
def run cmd, desc, *colours
print bold, blue, "#{desc}:", reset, "\n"
colours.each { |c| ... | true |
eb627ebcad9cff8c152a15e5789298b19ad20f2b | Ruby | Julppu/ruby-tehtava17 | /debugattava.rb | UTF-8 | 144 | 2.53125 | 3 | [] | no_license | module Debugattava
def tila
self.instance_variables.each do |var|
puts "#{var} #{self.instance_variable_get var}"
end
end
end
| true |
48a12d328c5f4cb8117cf74c7c5ea4ce0b243f03 | Ruby | bingo8670/ruby-programming-2.3 | /9.3.point.rb | UTF-8 | 570 | 3.984375 | 4 | [] | no_license | class Point
attr_accessor :x, :y
def initialize(x=0, y=0)
@x, @y = x, y
end
def [](index)
case index
when 0
x
when 1
y
else
raise ArgumentError, "out of range `#{index}`"
end
end
def []=(index, val)
case index
when 0
self.x = val
when 1
... | true |
202035873b137b2cb5582e6f4ed8744384400a2a | Ruby | jd1386/importer | /pt/slice-meta.rb | UTF-8 | 4,217 | 3.34375 | 3 | [] | no_license | require "csv"
require "awesome_print"
###
#
#
#
###
def format_date(raw, month)
year = raw.split(" ").last
result = "01/#{month}/#{year}"
return result
end
def format_pub_date(raw)
if raw.include? "janeiro"
month = "01"
result = format_date(raw, month)
elsif raw.include? "fevereiro"
month =... | true |
fb1b588a00daf92ea735126618f91af2d1fe9ee9 | Ruby | Galaxylaughing/hotel | /lib/hotel.rb | UTF-8 | 4,397 | 2.90625 | 3 | [] | no_license | module HotelBooking
class AlreadyReservedError < StandardError; end
class NonexistentIdError < StandardError; end
class Hotel
attr_reader :room_count, :price_per_night, :max_rooms_per_block, :blocks
attr_accessor :block_factory, :daterange_factory, :reservation_total
def initializ... | true |
f9d96c8f0515e1bbe81c24acb3bce0b8748c98db | Ruby | jetrockets/activerecord-update_counters_with_values | /lib/active_record/update_counters_with_values/class_methods.rb | UTF-8 | 672 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'active_record/update_counters_with_values/query_builder'
module ActiveRecord
module UpdateCountersWithValues
module ClassMethods
def update_counters_and_return_values(id, counters)
query = ActiveRecord::UpdateCountersWithValues::QueryBuilder.new(self).call(id, counters)
connection.... | true |
270f4182f9f5d460c1a117ff19d3a66d04270b8d | Ruby | pmichaeljones/tealeaf-week1 | /OrangeTree.rb | UTF-8 | 1,101 | 3.59375 | 4 | [] | no_license | class OrangeTree
attr_accessor :height, :age
def initialize()
@orange_count = 0
@height = 0 #these are inches
@age = 0
end
def count_the_orange
end
def pick_an_orange
@oranges = @oranges -= 1
end
def many_years_pass(years)
years.times do
one_year_passes
end
end
de... | true |
3906da55d30a502630bf6534fa46702b75eca54f | Ruby | lbirts/Coderbyte-Interview-Prep | /array_intersection.rb | UTF-8 | 186 | 2.96875 | 3 | [] | no_license | def FindIntersection(strArr)
res = (strArr[0].split(",").map(&:to_i) & strArr[1].split(",").map(&:to_i)).join(",").delete(" ")
if res.empty?
return false
end
return res
end
| true |
3b67780cc01322ffc378204b6199600a906d0003 | Ruby | mbarrerar/code | /app/services/space_service/ownership_checker.rb | UTF-8 | 244 | 2.515625 | 3 | [] | no_license | module SpaceService
module OwnershipChecker
OwnershipError = Class.new(StandardError)
def check_ownership!
unless space.owner?(current_user)
raise(OwnershipError, "User is not Space Owner")
end
end
end
end
| true |
dfbc9e30d473b8c08e9889d66de5e67176622a18 | Ruby | peter-james-allen/bank-tech-test | /lib/transaction.rb | UTF-8 | 441 | 3.171875 | 3 | [] | no_license | # frozen_string_literal: true
# Transaction class - stores information about a transaction
class Transaction
attr_reader :date, :credit, :debit, :start_balance, :end_balance
def initialize(amount, start_balance)
@credit = nil
@debit = nil
amount.negative? ? @debit = -amount : @credit = amount
@sta... | true |
0c1978e4c008a92b0602b9b2d535cb69befcba03 | Ruby | verg/jet_fuel | /jet_fuel.rb | UTF-8 | 616 | 2.640625 | 3 | [] | no_license | require 'sinatra'
require './jet_fuel/persisted_uri'
require './jet_fuel/uri_shortener'
class JetFuel < Sinatra::Base
get '/' do
uris = PersistedURI.all
erb :index , locals: { uris: uris }
end
post '/' do
short_urn = URIShortener.new.shorten(params["uri_to_shorten"])
PersistedURI.new(short_urn: ... | true |
723ac1d821f5e0821bf1da3bd54cd87a140834c0 | Ruby | bfl3tch/afternoon_zoo_2105 | /lib/animal.rb | UTF-8 | 253 | 3.53125 | 4 | [] | no_license | class Animal
attr_reader :kind, :weight, :age, :age_in_days
def initialize(kind, weight, age)
@kind = kind
@weight = weight
@age = "#{age} weeks"
@age_in_days = age * 7
end
def feed!(amount)
@weight += amount
end
end
| true |
5fc84577fac7f9397f3785fddb0ada0e449dbc0f | Ruby | jichen3000/colin-ruby | /metaprogramming_in_ruby/methods/roulette_method_missing.rb | UTF-8 | 532 | 3.390625 | 3 | [] | no_license | class Roulette
def method_missing(name, *args)
person = name.to_s.capitalize
number = 1
3.times do
number = rand(10) + 1
puts "#{number}..."
end
"#{person} got a #{number}"
end
end
if __FILE__ == $0
require 'minitest/autorun'
require 'm... | true |
024c8b627eac3d133d3d1d037a4648e9692bd9ee | Ruby | rubylogicgems/prawn-graph | /lib/prawn/graph/extension.rb | UTF-8 | 1,229 | 2.65625 | 3 | [
"MIT"
] | permissive | module Prawn
module Graph
module Extension
# Plots one or more Prawn::Graph::Series on a chart. Expects an array-like object of
# Prawn::Graph::Series objects and some options for positioning the sizing the
# rendered graph
#
# @param series [Array] of Prawn::Graph::Series obj... | true |
b351f6d06c8781057acc600ceff8daa09f77a458 | Ruby | webgago/xml_schema_mapper | /lib/xml_schema_mapper/builder.rb | UTF-8 | 4,186 | 2.515625 | 3 | [
"MIT"
] | permissive | class NoToXmlError < NoMethodError
end
module XmlSchemaMapper
class Builder
attr_reader :document, :parent, :namespace_resolver
def initialize(source, parent, namespace_resolver)
@parent = parent.is_a?(Nokogiri::XML::Document) ? parent.root : parent
@document = parent.docu... | true |
eeb5a9bbf60d0fb394fc31377d20ac28b3b9f215 | Ruby | KatrinSi/100K | /Person.rb | UTF-8 | 1,950 | 3.859375 | 4 | [] | no_license |
load 'Car.rb'
class Person
attr_accessor "first_name", "last_name", "cars", "money", "shoes", "age", "country"
def buy_car(any_car)
if self.money >= any_car.price
puts "Congratulations for buying #{any_car.name} #{any_car.model}!"
self.money -= any_car.price
puts "... | true |
17378f6ed36a2a1d486f9e3155b0f6dbd4a27353 | Ruby | rsterenchak/bubble_sort | /bubble_sort.rb | UTF-8 | 754 | 4.1875 | 4 | [] | no_license | # bubble_sort.rb
unsorted_array = [4, 3, 78, 2, 0, 2]
def bubble_sort(unsorted_array)
sorted_array = []
index = 0
# START METHOD
until unsorted_array == []
index = 0
while index < unsorted_array.length - 1
if unsorted_array[index] > unsorted_array[index + 1]
temp = unsorted_array[i... | true |
cc3179353630a3f00ce665597bdec83c0d0eb490 | Ruby | robertf0/100 | /intro_programming_book/arrays/exercise7.rb | UTF-8 | 84 | 3.15625 | 3 | [] | no_license | array_1 = [1, 2, 3, 4, 5]
array_2 = array_1.map { |num| num + 2}
p array_1
p array_2 | true |
f7beff81140bfae8ff7c6f5fe736cbe4c8c5f465 | Ruby | AlexBrandt46/Ruby-Factorial-Finder | /factorial_finder.rb | UTF-8 | 250 | 3.6875 | 4 | [] | no_license | puts "Give me the number you want to find the factorial of: "
initialValue = gets.chomp.to_i
i = initialValue
finalValue = 1
while i >= 1
finalValue = finalValue * i
i--
end
puts "The result of the factorial is: #{finalValue}"
response = gets.chomp | true |
102d01c7c7f2e9001db7ed08df067f3651500155 | Ruby | rickpeyton/project-euler-ruby | /problem_003.rb | UTF-8 | 303 | 3.890625 | 4 | [] | no_license | # Largest prime factor
# Problem 3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
require 'pry'
prime_factors = []
number = 13195
i = 2
while i < (number / 2)
prime_factors << i if number % i == 0
i += 1
end
puts prime_factors
| true |
66c518c2e871553ee76a7a865c257424c94bd97e | Ruby | dougtebay/my-select-001-prework-web | /lib/my_select.rb | UTF-8 | 275 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(collection)
if collection.length > 0
i = 0
new_collection = []
while i < collection.length
new_collection << collection[i] if yield(collection[i])
i += 1
end
new_collection
else
puts "This block should not run!"
end
end | true |
3902164ced3e240e86d8b0df45d7bf345e317f4e | Ruby | dbetm/cp-history | /URI/Principiante/4_ProductoSimple.rb | UTF-8 | 138 | 3.09375 | 3 | [] | no_license | # https://www.urionlinejudge.com.br/judge/es/problems/view/1004
a = gets.chomp.to_i
b = gets.chomp.to_i
res = a * b
puts("PROD = #{res}")
| true |
8192319c78ce329b92ea61e4eb7144657d603d5b | Ruby | ZJUguquan/Leetcode | /Timus-acm/1222.rb | UTF-8 | 256 | 3.5625 | 4 | [
"MIT"
] | permissive | # 1222
n = gets.chomp!.to_i
if n ==1
res = 1
elsif n==2
res = 2
else
if n % 3 == 0
res = 3**(n/3)
elsif n % 3 == 2
c = (n-2) / 3
res = 3**(c)*2
else # n % 3 = 1
c = (n-4)/3
res = 3**(c) *4
end
end
puts res | true |
ef6a188f05971414db4bb7485b74129f8fb36a79 | Ruby | Zeynab-j/ruby-enumerables-cartoon-collections-lab-part-1-nyc04-seng-ft-053120 | /cartoon_collections.rb | UTF-8 | 580 | 3.75 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def greet_characters(array)
# Use `each` to enumerate over the provided array
#
# Print a custom greeting for each element
characters_array = ["Dopey", "Grumpy", "Bashful"]
characters_array.each do |characters_array|
puts "Hello #{characters_array}!"
end
def list_dwarves(array)
# Use `each_with_index` to e... | true |
276344aa6b962818439d1144e04df2cd6c8818c8 | Ruby | plasmatic1/Advent-of-Code-2019 | /2019/d1t2.rb | UTF-8 | 222 | 3.453125 | 3 | [] | no_license | require_relative '../funs.rb'
require 'scanf'
f = rin(2019, 1)
def fuel x
req = x.div(3) - 2
if req <= 0
return 0
end
req + fuel(req)
end
ans = f.split("\n").map { |x| fuel x.to_i }.sum
puts ans
| true |
289d06abae52dd5f4589e037164171593457a2c0 | Ruby | JM3DWorks/Custodia | /test/models/entry_test.rb | UTF-8 | 2,017 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'test_helper'
class EntryTest < ActiveSupport::TestCase
def setup
@equipment = Equipment.new(name: 'Unit 59', description: 'Chevrolet Silverado 2008',
serial: '1GCEK19098Z148759', purchase_date: '2012-10-25')
@equipment.save
@entry = @... | true |
46517fd0cd8df3ee52b4658d504ef48d0afeb937 | Ruby | srycyk/templet | /lib/templet/renderers/erb.rb | UTF-8 | 1,891 | 2.671875 | 3 | [
"MIT"
] | permissive |
require 'erb'
require 'ostruct'
module Templet
module Renderers
# For rendering a supplied block within an ERb template
class ERb
attr_accessor :context, :proto_template
# template_path can be a local ERb file, template string, or DATA append
#
# locals are local variables for the E... | true |
fccc3af0346b2751987722051fb37629f064f9bd | Ruby | bctechnologies/dare0a-ruby | /test/test.rb | UTF-8 | 400 | 2.71875 | 3 | [] | no_license | require 'minitest/autorun'
class AssignmentTest < Minitest::Test
def test_greet
require 'assignment'
person = Person.new('Mary')
greet = person.greet('John')
assert_equal 'Hi John, my name is Mary', greet
person = Person.new('Paul')
greet = person.greet('Lisa')
assert_equal 'Hi Lisa, my ... | true |
91937c34017c3bd0ccaf01ed4b03ebc46f57a126 | Ruby | Johra444/tests-ruby | /lib/01_temperature.rb | UTF-8 | 201 | 3.6875 | 4 | [] | no_license | def ftoc(fahrenheit_degrees)
celsius = (fahrenheit_degrees.to_i - 32) * 5.0/ 9.0
celsius.round
end
def ctof(celsius_degrees)
fahrenheit = (celsius_degrees.to_i * 9.0/ 5.0) + 32
end | true |
17411457782939b2c6bd50207d14cee4d7d53787 | Ruby | rda1902/ruby_forking_tutorial | /basic_fork.rb | UTF-8 | 139 | 2.75 | 3 | [] | no_license | # basic_fork.rb
# A fork inherits the terminal of its parent process
fork do
sleep 2
puts "Fork: finished"
end
puts "Main: finished"
| true |
3c817e796c115f8124769e12bf43e26d245faf8f | Ruby | ChristinaLeuci/Ruby | /ErbAndHaml.rb | UTF-8 | 5,357 | 3.71875 | 4 | [] | no_license | The default templating language is Embedded Ruby(ERB)
In ERB we have three main markup elements:
HTML and text use no markers and appear plainly on the page
<%= and %> wrap Ruby code whose return value will be output in place
of the marker.
<% and %> wrap Ruby code whose return value will NOT be output.
<%- and %> wr... | true |
e8a26691752997499a98bff56238b147b3fbd004 | Ruby | emiellohr/paynl-rb | /lib/paynl/transaction_status.rb | UTF-8 | 871 | 2.6875 | 3 | [] | no_license | module Paynl
class TransactionStatus
CHARGEBACK = %w(-70 -71)
PAID_CHECKAMOUNT = %w(-51)
EXPIRED = %w(-80)
REFUND_PENDING = %w(-72)
REFUND = %w(-81)
PARTIAL_REFUND = %w(-82)
PENDING = %w(20 25 50 60 70 75 80 85 90)
OPEN = %w(60)
CON... | true |
e2aabdddae3a03b65bddbf0e0c703c36dd681ef2 | Ruby | kaledoux/ruby_small_problems | /Easy4/short_long_short.rb | UTF-8 | 1,834 | 4.84375 | 5 | [] | no_license | # Write a method that takes two strings as arguments,
# determines the longest of the two strings, and then returns the result of
# concatenating the shorter string, the longer string, and the shorter string
# once again. You may assume that the strings are of different lengths.
#
# Examples:
#
# short_long_short('abc'... | true |
fbae708fd007d37ce0c61a94875aa1dca5f17320 | Ruby | michaeljevans/battleship | /test/cell_test.rb | UTF-8 | 1,598 | 3.140625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/ship'
require './lib/cell'
class Celltest < MiniTest::Test
def test_it_exists
cell = Cell.new("B4")
assert_instance_of Cell, cell
end
def test_it_has_readable_attributes
cell = Cell.new("B4")
assert_equal "B4", cell.coordinate
... | true |
e0d13804517ffaf2bc5739990408b68a6ba50791 | Ruby | rameshsutaliya/RubyOnRails | /Source/Ch01/readingFromFile.rb | UTF-8 | 233 | 3.453125 | 3 | [] | no_license | =begin
Write a ruby program which reads the username from a text file and print the user name on the screen.
=end
def read_from_file
username = File.read("username.txt")
print "User name is :#{username}\n"
end
read_from_file()
| true |
f2c46e4faa45f75943af18886d307c3b404c8ddf | Ruby | abdelrauof97/breaking_news_cli_gem | /lib/data.rb | UTF-8 | 441 | 2.96875 | 3 | [
"MIT"
] | permissive |
require "colorize"
class Data
def self.get_data(url)
Scraper.get_and_sort_data(url).reject{|x| x[:title] == ""}
end
def self.exposing_news(url)
get_data(url).each.with_index(1) { |x,i|
if i < 11
puts ""
puts "#{i}. #{x[:title]}".colorize(:blue)
puts "ptess the link to see... | true |
ab9c2ea2a7b97b435d20767de8064babc4d2439e | Ruby | Narnach/fast_group_by | /spec/fast_group_by_spec.rb | UTF-8 | 314 | 2.609375 | 3 | [
"MIT"
] | permissive | require File.join(File.dirname(__FILE__),%w[.. lib fast_group_by])
describe Array, '#fast_group_by' do
it 'should return a Hash with key-Array pairs' do
ary = (1..10).to_a
groups = ary.fast_group_by {|e| e%2}
groups.should == {
0 => [2, 4, 6, 8, 10],
1 => [1, 3, 5, 7, 9]
}
end
end | true |
0b3f042a398986c3e9797336f9db18116e7d66a9 | Ruby | garciajordy/sales_tax_kata_advanced | /app/helpers/file_reader_helper.rb | UTF-8 | 573 | 2.71875 | 3 | [] | no_license | module FileReaderHelper
def file_reader(file)
basket = current_user.baskets.create(name: file.original_filename.split('.').first)
File.readlines(file).each do |line|
line_item_constructor(line_constructor(line), basket.id)
end
basket
end
def line_constructor(line)
{
quantity: line... | true |
111e07ec68cf6303dedd828d6bdf019bffebf269 | Ruby | joan2kus/ChartDirector | /railsdemo/app/controllers/scatter_controller.rb | UTF-8 | 2,390 | 2.625 | 3 | [
"IJG"
] | permissive | require("chartdirector")
class ScatterController < ApplicationController
def index()
@title = "Scatter Chart"
@ctrl_file = File.expand_path(__FILE__)
@noOfCharts = 1
render :template => "templates/chartview"
end
#
# Render and deliver the chart
#
def getchart()... | true |
6b19f2bb2511442c1b2c61c3afbafccaeb273b08 | Ruby | TonyCWeng/Practice_Problems | /leetcode/ruby/add_two_numbers.rb | UTF-8 | 951 | 4.1875 | 4 | [] | no_license | # leet code problem Add Two Numbers
# You are given two non-empty linked lists representing two non-negative integers.
# The digits are stored in reverse order and each of their nodes contain a single
# digit. Add the two numbers and return it as a linked list.
class ListNode
attr_accessor :val, :next
def initiali... | true |
07ce3cfa1f075c7ad6b5afee8bc919151fceb389 | Ruby | danielpaul/ruby-tldr | /1. Variables.rb | UTF-8 | 293 | 3.84375 | 4 | [] | no_license | puts 'Hello World!'
greeting = 'Good morning!'
puts greeting
forecast = "sunny" # string
temperature = 32 # number
is_summer = true # boolean
print "It's going to be #{forecast}, #{temperature} degrees outside today. "
# output to the same line.
print 'It\'s going to be a great day!'
| true |
dd348410551e44516adca5d28f84bcd5ab1c1e35 | Ruby | fanjieqi/LeetCodeRuby | /701-800/707. Design Linked List.rb | UTF-8 | 1,730 | 4.125 | 4 | [
"MIT"
] | permissive | class MyLinkedList
=begin
Initialize your data structure here.
=end
def initialize()
@array = []
end
=begin
Get the value of the index-th node in the linked list. If the index is invalid, return -1.
:type index: Integer
:rtype: Integer
=end
def get(index)... | true |
e5887a0bbed33b228cf2e7ddf3df8610464989f1 | Ruby | TheBitcoin/Prework | /Ruby Ironhack/data_types_in_ruby/data_types.rb | UTF-8 | 1,831 | 4.09375 | 4 | [] | no_license | # #data_types
# my_var = "This is a variable"
# pelicula = "Torrente 3"
# puts "My favourite movie is #{pelicula}"
# name = "miGuel"
# capitalized_name = name.capitalize
# puts "hello #{capitalized_name}"
# flavours = "chocolate, mint, strawberry, vanilla, caramel, chili"
# flavours_array = flavours.split(",")
# ... | true |
04f8c3db895ee843874c9a0eb52295a54e9f2e01 | Ruby | akchalasani1/myruby | /examples/ex21.rb | UTF-8 | 1,884 | 4.59375 | 5 | [] | no_license | =begin
Start from the inside and work out.
Divide iq by 2. Multiply that by weight. Subtract that from height. Add that to age.
In general, with nested parentheses, you always start from the innermost.
The purpose of parentheses in this type of formula is to manage the order that the operations occur,
Note: order of ... | true |
25c733311e925535926c5c0c73c519eb1d031bdb | Ruby | y-usuzumi/survive-the-course | /coursera/programming-languages/part-c/Week_1_Homework/hw6graphics.rb | UTF-8 | 2,189 | 3.359375 | 3 | [
"BSD-3-Clause"
] | permissive | # University of Washington, Programming Languages, Homework 6, hw6graphics.rb
# This file provides an interface to a wrapped Tk library. The auto-grader will
# swap it out to use a different, non-Tk backend.
require 'tk'
class TetrisRoot
def initialize
@root = TkRoot.new('height' => 615, 'width' => 205,
... | true |
003852429957e51daa6ff383fc0f97092e28d7b4 | Ruby | robsdrops/Ship-ice-simulation | /Content/grid.rb | UTF-8 | 688 | 3.15625 | 3 | [] | no_license | require_relative 'vector_and_point'
class Grid
attr_accessor :pointsArray, :horizontal_amount, :vertical_amount, :show, :size
def initialize size
@size = size
@pointsArray = []
@show = false
end
def calculatePoints
@pointsArray.clear if @pointsArray.any?
x = 0
y = 0
@horizontal_amount = (800.0 / @s... | true |
0aedd6f79fd1ff45ad1e4ffbc0d6eb974e3cef32 | Ruby | eva-barczykowska/Ruby | /Add_a_Key_Value_Pair_to_a_Hash.rb | UTF-8 | 255 | 3.734375 | 4 | [] | no_license | p menu = {burger: 3.99, taco: 5.96, chips: 0.50}
p menu[:sandwich] = 8.99
p menu
menu[:taco] = 2.99
p menu[:taco]
puts
#another way - the STORE method
#takes 2 arguments, key and value
menu.store(:sushi, 7.99)
p menu
menu.store(:steak, 9.99)
p menu
| true |
1caa0a10d45390174e9da2b9ad6518d07cb1ef60 | Ruby | rioyi/the-well-rounded-rubyist | /chapter_2/ticket-information-request.rb | UTF-8 | 249 | 3.171875 | 3 | [] | no_license | ticket = Object.new
def ticket.venue
"Town Hall"
end
def ticket.event
"Author's reading"
end
print "Information desired: "
request = gets.chomp
if request == "venue"
puts ticket.venue
elsif request == "event"
puts ticket.event
end | true |
92147699a0701f264bef2db01c2cc5788cd9e47c | Ruby | HurricaneJames/CWP | /app/models/game.rb | UTF-8 | 8,925 | 2.65625 | 3 | [] | no_license | class Game < ActiveRecord::Base
serialize :current_state, ApplicationHelper::JSONWithIndifferentAccess
validate :current_state_must_include_board_and_pieces
def board; current_state[:board]; end
def board=(board); current_state[:board] = board; end
def pieces; current_state[:pieces]; end
def pieces=(piece... | true |
f97d03cd9a91e5e31f187cbc170f79fdd92b47b2 | Ruby | ml242/ruby-frequency-txt-url | /freq.rb | UTF-8 | 642 | 3.296875 | 3 | [] | no_license | #open a url as if it's a standard file with a built in ruby library
require 'open-uri'
#This is Gutenberg's link to Hamlet
link = 'http://www.gutenberg.org/cache/epub/2265/pg2265.txt'
#read the link syntax
file = File.read(open(link))
#create an array of the file with the words split on spaces
words = file.to_s.split("... | true |
eb2e660114b5ca7b83426c687b162dcf9bd6424f | Ruby | kolyaventuri/module_3_diagnostic | /app/models/station.rb | UTF-8 | 837 | 2.921875 | 3 | [] | no_license | class Station
attr_reader :name, :address, :fuel_types, :distance, :access_times
def initialize(opts)
@name = opts[:name]
@address = opts[:address]
@fuel_types = opts[:fuel_types]
@distance = opts[:distance]
@access_times = opts[:access_times]
@fuel_types.gsub!('ELEC', 'Electric')
@fue... | true |
7acb6422cdae5fae5a8ec0fc8046de4dd08ae4b1 | Ruby | multi-io/xml-mapping | /examples/xpath_usage.intin.rb | UTF-8 | 1,031 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | #:invisible:
$:.unshift "../lib" #<=
#:visible:
require 'xml/xxpath'
d=REXML::Document.new <<EOS
<foo>
<bar>
<baz key="work">Java</baz>
<baz key="play">Ruby</baz>
</bar>
<bar>
<baz key="ab">hello</baz>
<baz key="play">scrabble</baz>
<baz key="xy">goodbye</baz>
</bar>
... | true |
21240851d0292e2866a94688dc6d7b1b3207912b | Ruby | DouglasAllen/facebook_group_files | /misc/vsop87.rb | UTF-8 | 9,719 | 2.8125 | 3 | [] | no_license | #!/usr/local/bin/ruby
require 'date'
require 'cgi'
# doc
class Clock
attr_accessor :date, :year, :month, :time, :day, :hour, :min, :sec
def initialize(date)
@date = date.to_datetime.to_time.utc
@time = @date
date_parts(date)
time_parts(date)
end
def time_in_day
@hour.to_f ... | true |
7336c751f53436207ec75c1e00d539d9ff214b04 | Ruby | jhallnation/ruby_test_pry | /string_reverser.rb | UTF-8 | 150 | 3.734375 | 4 | [] | no_license | #reverse a string without using the .reverse method
puts 'type in a ward'
s = gets.chomp
b = s.length - 1
while b >= 0
print s[b]
b = b - 1
end
| true |
ac8de51c510a3a8965615cf33d7bf7ea9f382ec5 | Ruby | GuilhermeMedeiross/Code-Wars | /1001 - Credit Card Mask.rb | UTF-8 | 263 | 3.03125 | 3 | [] | no_license | def mineMaskify(cc)
unmaks = cc.split(//).last(4).join
mask = cc.gsub(unmaks, "").gsub(/\w/, "#")
return mask + unmaks
end
def bestPraticeMaskify(cc)
cc.gsub(/.(?=....)/, '#')
end
cc = gets.to_s
puts mineMaskify(cc)
puts bestPraticeMaskify(cc) | true |
d8f4a4102b0c21056896a88b3dbc2e2dc9f7d7b9 | Ruby | Rudis1261/ruby-the-hard-way | /Exercises/game/scenes/tavern.rb | UTF-8 | 1,204 | 3.15625 | 3 | [] | no_license | class Tavern < Scene
def enter
message
choices([
"(Old Lady) I need to track down my Husband in the city. It's been over a month without so much as a word.\n (Me) I should find out more...",
"(Grimy welder to his friend) There's someone who found a vain of gold at the old mine, we should hea... | true |
5368ce0c8001f9984ba534d2e4600c9d6158ea8a | Ruby | al-nattahnam/ma-zmq | /lib/ma-zmq/proxy/balancer.rb | UTF-8 | 826 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module MaZMQ
class Proxy
class Balancer
@@strategies = [
:round_robin,
:connections,
:load, # Cucub podria usar algo como 'less_jobs'
:priority,
:directed
]
def initialize
self.strategy = :round_robin # default strategy is round_robin
@ind... | true |
551d46e2299fed9ef359391f41cd40bf9bec0714 | Ruby | infinitom/object_oriented_programming | /mars_rover.rb | UTF-8 | 1,698 | 4.6875 | 5 | [] | no_license | #
# OOP Exercise - mars_rover.rb
# A simple exercise to move an object on a grid using inputs such as
# Command - L (spin robot 90 degrees counter clockwise)
# Command - R (spin robot 90 degrees counter clockwise)
# Command - M (move forward in spun direction by one point)
#
class Rover
attr_accessor :x, :y, :direct... | true |
9f8416dcd9f9cabd20aa0bd321f3c426c9ed77f0 | Ruby | jtavarez14/cartoon-collections-onl01-seng-pt-032320 | /cartoon_collections.rb | UTF-8 | 788 | 3.21875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | dwarves = ["Doc", "Dopey", "Bashful", "Grumpy"]
def roll_call_dwarves(dwarves)
dwarves.each_with_index do |order_call, index|
puts "#{index + 1}. #{order_call}"
end
end
roll_call_dwarves(dwarves)
planeteer_calls = ["earth", "wind", "fire", "water", "heart"]
def summon_captain_planet(planeteer_calls)
planeteer... | true |
f7762318cffcd71a88e1008ac1cb06040501ea18 | Ruby | RudskikhIvan/dsl_parsers | /spec/field_methods_spec.rb | UTF-8 | 3,889 | 2.546875 | 3 | [
"MIT"
] | permissive | require "spec_helper"
class TestParser
include DslParsers::BaseParser
def self.default_finder
:xpath
end
def self.available_finders
[:xpath, :css, :regexp]
end
end
describe 'has_one methods' do
it 'build one level map' do
test_class = Class.new(TestParser) do
has_one :first_name, 'Us... | true |
ccc7f09988b13a4a0f9eec7b1abd262a7175390c | Ruby | dylanham/reddit-pair-app | /spec/feature/posts_management_spec.rb | UTF-8 | 3,601 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
feature 'User can do lots of stuff with posts' do
scenario 'Only a logged in user can make a new post' do
user = create_user
login(user)
expect(current_path).to eq root_path
click_on "New Post"
fill_in "Title", with: "My Favorite Post Ever"
fill_in "Content", with: "I ... | true |
bc62e2c7e43425acaaa7bdeb2e61401d96eb51bc | Ruby | Viola100/codesensei_course | /homework_1/5.rb | UTF-8 | 150 | 2.890625 | 3 | [] | no_license | puts "Podaj dystans w km"
km = gets.to_f
spalanie = km * 0.065
puts "Zużycie paliwa: #{spalanie}"
koszt = spalanie * 4.30
puts "koszt: #{koszt} zł"
| true |
7b92aeff260e0a56dd2f4c5042866a1c0e7f807b | Ruby | pcruiksh/rmmts | /app/models/purchase.rb | UTF-8 | 1,006 | 2.765625 | 3 | [] | no_license | class Purchase < ActiveRecord::Base
belongs_to :mate
has_many :payments, dependent: :destroy
has_one :house, through: :mate
mount_uploader :image, BillUploader
def amount_paid
paid = self.payments.sum(:amount)
end
def amount_owed
owed = (self.amount_paid + self.amount_for_each) - self.amount
... | true |
d11235188fd0fdb7e2c9149d313cfa34013d73a9 | Ruby | martinliptak/codility | /S-MinAvgTwoSlice.rb | UTF-8 | 1,352 | 3.484375 | 3 | [
"MIT"
] | permissive | # you can use puts for debugging purposes, e.g.
# puts "this is a debug message"
def solution(a)
sums = prefix_sums(a)
min = nil
min_from = nil
(0..a.count - 2).each { |i|
(i + 1..[i + 4, a.count - 1].min).each { |j|
avg = (sums[j + 1] - sums[i]).to_f / (j - i + 1)
if mi... | true |
091ab108ee03ccb53b3f4633145823ad90509121 | Ruby | mynameisrufus/sorted | /lib/sorted/elasticsearch_query.rb | UTF-8 | 652 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'sorted/set'
module Sorted
##
# Parses an Elasticsearch type set of order
#
# Parsing:
#
# params = [{ 'email' => {'order' => 'desc'}}]
# set = Sorted::ElasticsearchQuery.parse(params)
# set.to_a #=> [['email', 'desc']]
#
# Encoding:
#
# Sorted::ParamsQuery.encode(set) #=> [{ 'e... | true |
8f40646d643ec1085ac8e950718c46a907e76392 | Ruby | ParkMD7/reverse-each-word-nyc-web-080618 | /reverse_each_word.rb | UTF-8 | 266 | 3.640625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | sentence1 = "Hello there, and how are you?"
sentence2 = "Hi again, just making sure it's reversed!"
def reverse_each_word(sentence)
sentence = sentence.split
sentence.collect do |word_reverse|
word_reverse.reverse!
end
sentence.join(" ")
end
| true |
d8a0c6eed6c09833332eb03eb9fe1d6903d89956 | Ruby | fzhou7/ruby | /09_timer/timer.rb | UTF-8 | 226 | 3.109375 | 3 | [] | no_license | class Timer
attr_accessor :seconds
def initialize()
@seconds = 0
end
def time_string
"#{"%.2i" %(hour=seconds/3600)}:#{"%.2i" %(minute=(seconds-hour*3600)/60)}:#{"%.2i" %(seconds-hour*3600-minute*60)}"
end
end | true |
14a2a197f0f3da0fb0310f657848701277206469 | Ruby | PetePhx/ruby-tests | /exercises/easy_testing/04_empty_object_assertions.rb | UTF-8 | 978 | 2.984375 | 3 | [] | no_license | =begin
Empty Object Assertions
Write a minitest assertion that will fail if the Array list is not empty.
=end
require 'minitest/autorun'
require 'minitest/reporters'
Minitest::Reporters.use!
class EmptyTest < Minitest::Test
def setup
@arr1 = []
@arr2 = %w[I can haz test]
end
def test_empty
asser... | true |
a9f5a037874fbc3b875c958b03db98ecf015538d | Ruby | KaiserChan/ruby_fundamentals_1 | /exercise4.1.rb | UTF-8 | 187 | 3.921875 | 4 | [] | no_license | puts "Hey there, what is the number that you are thinking of now?"
number = gets.chomp.to_i
if number >= 100
puts "That's a big number!"
else
puts "Why? Dream a little bigger!"
end
| true |
052a284dab5b84841dcbc8ef9cd0233e1c74397d | Ruby | BJSummerfield/Prework | /prework/Episode21/Exercise2.rb | UTF-8 | 64 | 3.078125 | 3 | [] | no_license | number = -2
51.times do
number = number + 2
puts number
end | true |
8ebf289a649ecbddb4cabb59bfa582066fcdba95 | Ruby | dsaenztagarro/gundam | /lib/gundam/github/api/v3/connector.rb | UTF-8 | 5,088 | 2.546875 | 3 | [] | no_license | # frozen_string_literal: true
require 'octokit'
require_relative 'mappers/combined_status_ref_mapper'
require_relative 'mappers/commit_status_mapper'
require_relative 'mappers/comment_mapper'
require_relative 'mappers/issue_mapper'
require_relative 'mappers/label_mapper'
require_relative 'mappers/pull_request_mapper'... | true |
9ceee1213ceb97328f7e738ef50a87dad7c5eee0 | Ruby | Gia1987/Ruby-Bank-Tech-Test | /lib/printer.rb | UTF-8 | 249 | 3.171875 | 3 | [] | no_license | class Printer
def header
"date || Credit || Debit || Balance\n"
end
def print_statement(history)
string = ''
history.reverse.map{ |row| string += " #{row[0]} || " + "#{row[1]} || " + "#{row[2]}\n" }
header + string
end
end
| true |
98836efb8265b8d38a690daf5430bd6d43d4cf99 | Ruby | arirusso/pulse-analysis | /lib/pulse-analysis/audio_data.rb | UTF-8 | 1,093 | 3.078125 | 3 | [
"Apache-2.0"
] | permissive | module PulseAnalysis
class AudioData
extend Forwardable
def_delegators :@data, :[], :count, :each, :length, :max, :min, :size
# @param [PulseAnalysis::Sound] sound
def initialize(sound)
@sound = sound
@data = @sound.data
end
# Prepare the audio data for analysis
# @return ... | true |
3efa945b2d8107742b76a7752614347a533ff841 | Ruby | jasmine-carter/ruby-collaborating-objects-lab-online-web-sp-000 | /lib/song.rb | UTF-8 | 676 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
attr_accessor :name, :artist
@@all = []
def initialize(name)
@name = name
save
end
def save
@@all << self
end
def self.all
@@all
end
def artist_name=(name)
artist_name = Artist.find_or_create_by_name(name)
@artist = artist_name
#check to see if a... | true |
134e6d4a32f676d48e2c7acd0689ff6aba141ea4 | Ruby | PlaustralCL/mastermind | /test/clues_test.rb | UTF-8 | 1,974 | 2.65625 | 3 | [] | no_license | # frozen_string_literal: true
require "test_helper"
require_relative "../lib/mastermind/clues"
# Tests for class Clues
class CluesTest < Minitest::Test
def test_keys_returns_empty_when_no_matches
code = 1233.digits.reverse
guess = 5555.digits.reverse
clue = MasterMind::Clues.new(guess: guess, code: code... | true |
99c1e6858dad4d366083e232fca0e4e844867fba | Ruby | joelhelbling/arche | /spec/lib/arche/function_spec.rb | UTF-8 | 1,009 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'arche/type'
require 'arche/function'
module Arche
describe Function do
it { should be_kind_of Arche::Type }
it "has a Proc as its function" do
subject.instance_eval("@function").should be_kind_of(Proc)
end
it "can be constructed with a Proc" do
subject = Function.new { "fooBAR"... | true |
80af3b8a7135fad57ffbca3954365b17e5229643 | Ruby | gpepic/shoes_rb_sql | /lib/style.rb | UTF-8 | 520 | 3.09375 | 3 | [] | no_license |
class Style
def initialize(name, id=nil)
@name = name
@id = id
end
def name
@name
end
def id
@id
end
def ==(another_style)
self.name == another_style.name
end
def self.all
results = DB.exec("SELECT * FROM style;")
style = []
results.each do |result|
name = result['name']
id = result... | true |
350f4f045c15bb4fa40240858a60bd670452c69a | Ruby | Fred-209/RB100 | /ruby_basics_exercises/loops/thats_odd.rb | UTF-8 | 253 | 4.28125 | 4 | [] | no_license | # he code below shows an example of a for loop. Modify the code so that it only outputs i if i is
# an odd number.
for i in 1..100
puts i if i.odd?
end
# or using modulo to determine if a number is odd
for i in 1..100 do
puts i if i % 2 != 0
end
| true |
905608926e68cb3bdb6479ef5d6ca4bfd6500cd0 | Ruby | holodigm/winnr | /lib/random_range.rb | UTF-8 | 256 | 3.234375 | 3 | [] | no_license |
def rand_int(from, to)
rand_in_range(from, to).to_i
end
def rand_price(from, to)
rand_in_range(from, to).round(2)
end
def rand_time(from, to)
Time.at(rand_in_range(from.to_f, to.to_f))
end
def rand_in_range(from, to)
rand * (to - from) + from
end
| true |
f9d3d63e77767d6796d5421929c369e91a387fb8 | Ruby | nittan02/ruby | /file.rb | UTF-8 | 2,028 | 3.75 | 4 | [] | no_license | #! /usr/bin/ruby -Ks
puts "------------------------------------------------------"
begin
# File.openはファイルをオープンし、Fileオブジェクトを返す
# 第一引数: ファイルパス
# 第二引数: ファイルモード(デフォルト "r")
# 第三引数: ファイルを生成する場合のパーミッション
# 失敗した場合にErrno::EXXX例外が発生
#
# File.openにブロックを渡すと、
# ブロックを閉じた時点でファイルを自動クローズする。
File.open('./inputFile.... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.