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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
70bfe5388fa629279139b405b0d252e81123889a | Ruby | mdimannyit/shopify-snippets-2 | /line-item-scripts/buy-more-save-more/no-discount-code.rb | UTF-8 | 1,523 | 2.65625 | 3 | [] | no_license | # Tier One Threshold, Discount, and Percentage
TIER_ONE_THRESHOLD = 0
TIER_ONE_DISCOUNT = Decimal.new(10) / 100.0
TIER_ONE_MESSAGE = "10% Off"
# Tier Two Threshold, Discount, and Percentage
TIER_TWO_THRESHOLD = 51
TIER_TWO_DISCOUNT = Decimal.new(15) / 100.0
TIER_TWO_MESSAGE = "15% Off"
# Tier Three Threshold, Discoun... | true |
35251f43234360505027974ac8bfe6519efc04fc | Ruby | ryuchan00/ruby_for_beginners | /sample/ensure.rb | UTF-8 | 372 | 3.015625 | 3 | [] | no_license | # 9.6.2 ensureの代わりにブロックを使う
# ブロック付きでオープンすると、メソッドの実行後に自動的にクローズされる
File.open('some.txt', 'w') do |file|
file << 'Hello'
1 / 0
end
# 例外は発生するものの、openメソッドによってクローズ処理自体は必ず行われる
# => ZeroDivisionError: divided by 0
| true |
08b2be6c4b4e36fa4c9b845fdd61d59973837931 | Ruby | MicFin/ga-twitter-stock-sinatra-lab | /main1.rb | UTF-8 | 731 | 2.546875 | 3 | [] | no_license |
require 'twitter'
require 'pry'
require 'dotenv'
require 'stock_quote'
require 'sinatra'
require 'sinatra/reloader' if development?
Dotenv.load
set :server, 'webrick'
def twitter(company)
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
config.consumer_secre... | true |
4d85f8e1eda359ac7d3c66658d6ddbe728897300 | Ruby | danielcpan/tic_tac_toe | /tic_tac_toe.rb | UTF-8 | 894 | 3.890625 | 4 | [] | no_license | class TicTacToe
def initialize(game_mode)
@game_mode = game_mode
start_game
end
def start_game
display_instructions
draw_board
end
def display_instructions
puts "Enter 1-9 to place on that tile (Q to quit game)"
end
def draw_board
tile = [1, 2, 3, 4, 5, 6, 7, 8, 9]
puts (" #{tile[0]} | #{tile... | true |
d03aa89ae6e774a0653b03ebc92ca06672ade90f | Ruby | oscaralbertoag/ruby-practice-excercises | /chatroom-status/spec/chatroom_status_spec.rb | UTF-8 | 834 | 2.578125 | 3 | [] | no_license | require "rspec/autorun"
require_relative "../lib/chatroom_status_solution.rb"
describe "chatroom_status()" do
test_cases = [[[], "no one online"],
[["becky325"], "becky325 online"],
[["becky325", "malcolm888"], "becky325 and malcolm888 online"],
[["becky325", "malcolm8... | true |
7872b84ce696672d3261282d54d2ce300d876e24 | Ruby | hiroyuki-sato/pgroonga_like_test | /sample_gen.rb | UTF-8 | 460 | 2.703125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'csv'
require 'securerandom'
require 'uri'
urls = %w[
http://aa.yahoo.co.jp/
http://ab.yahoo.co.jp/
http://ac.yahoo.co.jp/
http://ad.yahoo.co.jp/
http://ae.yahoo.co.jp/
]
idx = 1
urls.each do |url|
%w[ aa bb cc dd ee ].each do |p|
1.upto(1000).each do |n|
# print [idx... | true |
461127b6aab6caaf7fb879ef7501c3ac8e095a7c | Ruby | AbbyJonesDev/AJAX_Puppy_HQ | /spec/controllers/puppies_controller_spec.rb | UTF-8 | 7,573 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold... | true |
bf101626442f0699b4e3f5832dc1794231165322 | Ruby | ekearm/budgiet_finance | /Budgiet/budgietv1.rb | UTF-8 | 808 | 3.765625 | 4 | [] | no_license | class Paycheck
def initialize
attr_accessor :name, :last_amnt
end
puts "Hello, I am Budgiet your personal finance and budget assistant. Lets start by getting your name."
p1 = gets.chomp
puts "Nice to meet you #{p1}"
puts "First to get started with how many jobs with pay checks do you have?"
num_p... | true |
f6b02d9ee5ced880804374ff22b09dff14e826f3 | Ruby | howclf/RubyCode | /simple_grep.rb | UTF-8 | 186 | 3.328125 | 3 | [] | no_license | # simple example to grep files
pattern = Regexp.new(ARGV[0])
filename = ARGV[1]
file = open(filename)
while text = file.gets do
if pattern =~ text
print(text)
end
end
file.close
| true |
d9c748c211f2de316b4cff563d8ec3763d6f07c1 | Ruby | bryanstearns/fest2 | /config/initializers/basic_type_extensions.rb | UTF-8 | 2,573 | 3.296875 | 3 | [] | no_license | module TimeExtensions
# Add step() to times, too
def step(limit, step)
v = self
while v < limit
yield v
v += step
end
end
def date
# Get the date corresponding to this time
Date.civil(self.year, self.month, self.day)
end
def parts(include_zero_minutes=true)
# Get the ... | true |
cbec435fb8e5c86d3f337ec312b9a88f8b5c215c | Ruby | ualbertalib/sufia_migrate | /lib/sufia_migrate/export/versions_from_graph.rb | UTF-8 | 1,394 | 2.984375 | 3 | [] | no_license | # frozen_string_literal: true
module Export
class VersionsFromGraph
attr_accessor :versions
class Version
attr_accessor :uri, :label, :created
def initialize(uri, label, created)
@uri = uri
@label = label
@created = created
end
end
# Converts a graph with v... | true |
159292ade12b835dd0d560a5ad09fd149a6dd222 | Ruby | jonashermann/a_real_web_server_and_browser | /server.rb | UTF-8 | 1,227 | 2.984375 | 3 | [] | no_license | require 'socket'
require 'json'
server = TCPServer.open(3000)
loop{
Thread.start(server.accept)do |client|
#REVIEW: short-term fix solution
#for reading request from client
#research others solutions.
#read_nonblock(256)?
request = client.read_nonblock(256)
request_headers, request_body = request.split... | true |
046582c0b0f329eb852cef4a5f4ffd238c86d176 | Ruby | monicamendesmontanha/warmup | /06_scrabbleScore/scrabble_score.rb | UTF-8 | 1,840 | 4.65625 | 5 | [] | no_license | # Write a program that, given a word, computes the scrabble score for that word.
# scrabble("cabbage")
# # => 14
# Your program should be in a file named scrabble.rb. You should be able to compute the score for any word entered by the user.
# Letter Values
# Letter Value
# A, E, I, O, U, L, ... | true |
5825e8f778d9416ff470a95d88cc3059bca0c800 | Ruby | matttproud/ruby_quantile_estimation | /profile/quantile.rb | UTF-8 | 608 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'ruby-prof'
require 'time'
require_relative '../lib/quantile'
runs = 2 ** 12
time = Time.now.strftime('%Y-%m-%d-%H-%M-%S')
estimator = Quantile::Estimator.new
{
:observe => lambda { |_| estimator.observe(rand) },
:query => lambda { |_| estimator.query(0.5) },
}.each do |report, test|
profile = RubyPro... | true |
ddec34535b56b8a11dc5cb0a35b7626bb1e5c5ee | Ruby | aliashafi/W4D3 | /chess/modules/stepable.rb | UTF-8 | 311 | 2.734375 | 3 | [] | no_license | module Stepable
def moves
dirs = self.move_diffs # give us offsets for piece
current_pos = self.pos #current_pos
all_moves = []
dirs.each do |offset|
all_moves << [current_pos[0] + offset[0], current_pos[1] + offset[1]]
end
all_moves
end
private
def move_diffs
end
end | true |
b309477243b286f4ae6cf41a1d0e370f24f0b3d0 | Ruby | Nerajno/many-to-many-through-event-ticket-attendee | /many-to-many-through-event-ticket-attendee/tools/console.rb | UTF-8 | 1,088 | 3.109375 | 3 | [] | no_license | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
# Insert code here to run before hitting the binding.pry
# This is a convenient place to define variables and/or set up new object instances,
# so they will be available to test and play around with in your console
#Example of ... | true |
99c25504444f405cfddf00b75a6455e503bbd26d | Ruby | ppibburr/GirFFISugar | /lib/GObject/lib/payload.rb | UTF-8 | 1,779 | 2.59375 | 3 | [] | no_license | require File.join(File.dirname(__FILE__),"ffi.rb")
require File.join(File.dirname(__FILE__),"subclass_normalize.rb")
module GObject
load_class :Object
class Object
# set's up the farthest ancestor's method
# q, method name, String|Symbol
# b method body, optional, if passed, defines method q
def se... | true |
3552f28dcbfebd55c601d08b30ed0effa925b2ed | Ruby | calb3ars/aa2 | /w2/w2d1/exercises/lib/00_rpn_calculator.rb | UTF-8 | 1,166 | 3.953125 | 4 | [
"MIT"
] | permissive | class RPNCalculator
OPERATORS = [:+, :-, :*, :/]
def initialize
@stack = []
end
def push(el)
@stack << el
end
def evaluate(string)
tokens(string).each do |char|
case char
when Integer
push(char)
when Symbol
perform_op(char)
end
end
value
end
... | true |
f2c93a62dd3345b0feec19b3b4edc7044c5b1e45 | Ruby | nkelton/wik-wak | /app/services/factories/vote_factory.rb | UTF-8 | 1,150 | 2.640625 | 3 | [] | no_license | module Factories
class VoteFactory < Factory
Result = Struct.new(:response, :errors, :code, keyword_init: true)
SUCCESS = "success"
ERROR = "error"
POST_NOT_FOUND_ERROR = "Post Not Found"
POST_NOT_CREATED = "Post Could Not Be Created"
def initialize
... | true |
0ae6f0f6ea4cb854f914aaefd77f52d2202701f2 | Ruby | indepat/Intro-Programming | /6_Arrays/Arrays_Exercise3.rb | UTF-8 | 164 | 3.078125 | 3 | [] | no_license | #How do you return the word "example"
#from the following array?
arr = [["test", "hello", "world"],["example", "mem"]]
arr.last.include?("example")
#Returned True
| true |
1658b127c37073c5cd4c25bce2cd8171287bea2e | Ruby | brentgreeff/acts_as_human | /spec/acts_as_human_spec.rb | UTF-8 | 5,014 | 2.6875 | 3 | [
"MIT"
] | permissive | class Model < ActiveRecord::Base
end
RSpec.describe ActsAsHuman do
context 'A Model that acts as a human' do
before do
Model.class_eval do
acts_as_human
end
end
context 'when the user is new' do
let(:user) { Model.new }
it 'has an empty full_name' do
expect( user... | true |
636ac7e3f60ae35fe9535c12505c38c2e543db0e | Ruby | iazigit/thp-homework | /rubyDay1/exo_19.rb | UTF-8 | 210 | 2.5625 | 3 | [] | no_license | fake_emails = []
for i in 1..100
fake_emails << "jean.mouloud#{i.to_s.rjust(3,'0')}@yahoo.fr"
end
puts fake_emails
fake_emails.each_with_index do |email, index|
if index %2 == 0
puts email
end
end
| true |
2ad4dd8fb488c1fa66b9c9deeced9ea7e47f366b | Ruby | david50407/eatwhat | /dict.rb | UTF-8 | 294 | 2.84375 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
class EatWhatDict
attr_reader :foods
attr_reader :ops
@foods = []
@ops = []
def initialize
@foods = []
@ops = []
end
def foods=(val)
puts "dict here!"
@foods = val.uniq
end
def ops=(val)
@ops = val.uniq
end
end
| true |
dede35ff36694bf100f438e6b9d12d5a97ecadde | Ruby | fcarlosdev/the_odin_project | /tdd/caesar_cipher/spec/caesar_cipher_spec.rb | UTF-8 | 1,130 | 3.375 | 3 | [] | no_license | require './caesar_cipher'
describe "Caesar Cipher" do
def load_cipher(word,key)
ciphred_characteres = cipher(word,key)
ciphred_characteres
end
context "with the word or a letter and a key provided" do
it "cipher the given word by a key" do
expect(load_cipher("tomorrow",7)).to eq("avtvyyv... | true |
286cd518bf61ed6d65fa27528b17a65ee2b179a2 | Ruby | amittauro/BorisBikes | /test_framework.rb | UTF-8 | 281 | 3.625 | 4 | [] | no_license | require 'colorize'
def assert_equals(val1, val2)
val1 == val2
end
def it(description, &block)
result = block.call # return a boolean (hopefully)
if result == true
puts "#{description}: Yeah, Great!".green
else
puts "#{description}: Try again... :(".red
end
end
| true |
3d41fb828cfa4f11da2b202e642ba4887a7cf597 | Ruby | mikechau/edx | /cs-169.1x/Week 2/hw1/part1.rb | UTF-8 | 621 | 3.5625 | 4 | [] | no_license | #For those just starting out, one suggested way to work on your code is to have a command window open and a text editor with this
#file loaded. Make changes to this file and then run 'ruby part1.rb' at the command line, this will run your program. Once you're
#satisfied with your work, save your file and upload it to... | true |
e2953db2e01a3595ca30c54a3b98ea8fd2147d0e | Ruby | zhisme/notes_backend | /app/services/collection_builder.rb | UTF-8 | 1,396 | 2.78125 | 3 | [] | no_license | class CollectionBuilder
attr_reader :params, :collection
DEFAULT_SORT_DIR = :desc
class CollectionNotBuilded < StandardError; end
def self.call(params, collection)
new(params, collection).call
end
def call
return search if SqlCommandDefiner.search?(params)
return sort if SqlCommandDefiner.so... | true |
d1093128887ae698e8d82503352705c5ee139369 | Ruby | TomYang1993/OOP_easy_example | /store_item.rb | UTF-8 | 603 | 3.625 | 4 | [] | no_license | # item1 = {name: "apple",price: 40, weight: 3}
# item2 = {name: "peach",price: 30, weight: 2}
# item3 = {name: "kiwi" ,price: 20, weight: 1}
module Storefont
class Store
attr_reader :name, :price, :weight
def initialize(input)
@name = input[:name]
@price = input[:price]
@weight = input[:weig... | true |
9cede565fb636b1f98f7f17407adf6f6e9758212 | Ruby | spraints/t | /lib/t/commands/since.rb | UTF-8 | 877 | 2.765625 | 3 | [
"MIT"
] | permissive | require 't'
require 't/data'
module T
module Commands
class Since
def initialize(options = {})
@stdout = options.fetch(:out) { $stdout }
@file = options.fetch(:file) { T::DATA_FILE }
@time = options.fetch(:time) { Time }
@act = options.fetch(:act) { T.activity_words }... | true |
3e625939605dd4807378b8a99f4fb0de4dd0657d | Ruby | NUOCW-Project/ocw-design-en | /scripts/mb_check.rb | UTF-8 | 2,170 | 2.84375 | 3 | [] | no_license | # In ruby 1.6.8, 'open-uri' and 'optparse' library can not be used...
require 'getoptlong'
require 'net/http'
Net::HTTP.version_1_2
# Regular Expressions for a multibyte character
shift_jis = /[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]/n
euc_jp = /[\xa1-\xfe][\xa1-\xfe]/n
utf8 = / [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef]... | true |
d5c078bfd4ac6cb4abb199d34454567f1bf54bcb | Ruby | HNH12/Design-Pattern | /Ruby/Седьмая_лаба/WorkWithDB.rb | UTF-8 | 4,186 | 2.78125 | 3 | [] | no_license | require_relative 'Employee.rb'
require_relative 'Post'
require 'mysql2'
class DB_work
@@DB_connection = nil
# private_class_method :new
def initialize
@client = Mysql2::Client.new(
:host => 'localhost',
:username => 'root',
:database => 'stuff'
)
end
def self.DB_connection
if... | true |
d92ad1ff01f809548ad449713e76694df67c627d | Ruby | Whapow/overlord-shovel-backend | /spec/models/stack_spec.rb | UTF-8 | 2,262 | 2.6875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Stack do
let (:inventory) { create :inventory }
let (:item1) { create :item }
let (:item2) { create :item }
let (:stack1) { create :stack, inventory: inventory, item: item1, position: 1 }
let (:stack2a) { create :stack, inventory: inventory, item: item2, position: 2 }
... | true |
23b6bfb29f3e9daef41d57527cc6f56dbaf99271 | Ruby | awesome-academy/naitei-ruby-2020-airport-workspace-management | /awm-api/lib/helpers/password_reset_helper.rb | UTF-8 | 718 | 2.515625 | 3 | [] | no_license | module PasswordResetHelper
def check_expiration user
is_expired = user.password_reset_expired?
error!(I18n.t("errors.expired_reset_password_token"), :bad_request) if is_expired
end
def check_blank_password
error!(I18n.t("errors.blank_password"), :bad_request) if params[:password].blank?
end
def ... | true |
e55bd5f8e416f7b47587ff96048a29fd8da26625 | Ruby | TylerTaylor/reverse-each-word-v-000 | /reverse_each_word.rb | UTF-8 | 410 | 3.53125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #def reverse_each_word(string)
# reversed_words = []
# new_string = string.split(" ")
# new_string.each do |word|
# reversed_words << word.reverse
# end
# reversed_words.join(" ")
#end
def reverse_each_word(string)
new_string = string.split(" ")
reversed_words = []
new_string.collect... | true |
2f4c4387c7fb593bc94f35b0d711cfbba7020bec | Ruby | liberatus/insightexchange_gem | /spec/insightexchange_spec.rb | UTF-8 | 3,231 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe InsightExchange do
let(:api_token) { 'abc123' }
let(:exchange) { InsightExchange.new(api_token) }
describe 'reading options from ENV variables' do
before { ENV['INSIGHT_EXCHANGE_TOKEN'] = api_token }
after { ENV['INSIGHT_EXCHANGE_TOKEN'] = nil }
it 'reads INSIGHT_EXCH... | true |
137e0f1f4995df7c5e46d896b9324b1788ad6ef9 | Ruby | inesikhlef/Pair-Programming | /exo_11.rb | UTF-8 | 177 | 3.5625 | 4 | [] | no_license | puts "Donne moi un nombre !"
number = gets.chomp.to_i
number.times do
puts "Salut, ca farte ?"
end
#l'utilisateur va rentrer un nombre, la phrase va s'afficher au meme nombre | true |
7c50bdcaacdef53288e7800eb68a90b2a7c2fdc7 | Ruby | geekdreamzz/epiphany | /app/models/epiphany/config.rb | UTF-8 | 393 | 2.71875 | 3 | [
"MIT"
] | permissive | module Epiphany
class Config
def auth_handler
@auth
end
def auth=(method_name)
@auth = method_name
end
class << self
def set
yield config
end
def has_auth?
config.auth_handler.present?
end
def auth
config.auth_handler
en... | true |
20e9e63cda152da2da958422ef9d501a8c8d228b | Ruby | bibikovilya/summer-2019 | /3485/3/app/models/comment.rb | UTF-8 | 431 | 2.515625 | 3 | [] | no_license | class Comment < ActiveRecord::Base
validates :raiting, presence: { message: 'Rate it!' }
validates :text, presence: { message: 'Write a review!' }, if: :too_low_raiting
belongs_to :user
belongs_to :restaurant
after_save :update_raiting
def too_low_raiting
raiting ? raiting < 3 : false
end
private
... | true |
53efdae3b96d90eb7ce1a8ca6b43a4592d89d22b | Ruby | Code4PuertoRico/suministrospr-web-scraper | /suministrospr_web_scraper.rb | UTF-8 | 2,424 | 2.53125 | 3 | [] | no_license | # encoding: UTF-8
require 'i18n'
require 'kimurai'
require 'mechanize'
require 'sanitize'
class SuministrosPR < Kimurai::Base
DATA_DIR = File.expand_path('data', __dir__).freeze
ALL_DATA_FILES_PATH = File.join(DATA_DIR, '*.json').freeze
@name = "suministrospr-web-scraper"
@engine = :mechanize
@start_urls =... | true |
7ac058697bc43d7d2f1debfdcef0bc314cb5c4fb | Ruby | ilyafaybisovich/LRTHW | /ex19.rb | UTF-8 | 983 | 4.59375 | 5 | [] | no_license | def cheese_and_crackers(cheese_count, boxes_of_crackers)
puts "You have #{cheese_count} cheeses!"
puts "You have #{boxes_of_crackers} boxes of crackers!"
puts "Man that's enough for a party!"
puts "Get a blanket.\n"
end
puts "We can just give the function numbers directly:"
cheese_and_crackers(20, 30)
puts ... | true |
321e56483b79f8c1e66bdf3bf2286ef88822bf49 | Ruby | nkinney/rrobots | /LCF/destination_setter.rb | UTF-8 | 769 | 3.078125 | 3 | [] | no_license | class DestinationSetter
attr_reader(:damage_taken)
attr_reader(:ticks_used)
def initialize battlefield_width, battlefield_height, clipping_offset
@damage_taken = 0
@ticks_used = 0
@battlefield_width = battlefield_width
@battlefield_height = battlefield_height
@clipping_offset = clipping_offse... | true |
75f7fde453b2f9f9caa3bf06e6e34d73a9d22b57 | Ruby | toshinori/flms | /app/models/member.rb | UTF-8 | 1,540 | 2.796875 | 3 | [] | no_license | class Member < ActiveRecord::Base
acts_as_paranoid
validates_as_paranoid
belongs_to :position
has_one :team_member, dependent: :destroy
has_one :team, through: :team_member
has_many :game_members
validates :first_name,
presence: true,
length: { maximum: 10 }
validates :last_name,
presenc... | true |
30207e3ffacb95da6340d1ac0c02e2079ae10f53 | Ruby | ajith-u/R2 | /r2.rb | UTF-8 | 109 | 2.84375 | 3 | [] | no_license | r,s=gets.chomp.split.map(&:to_i)
if s.between?(-1000,1000) and r.between?(-1000,1000)
puts (s*2)-r
end
| true |
c6e2e3354429a837edfa49a5dadbfff0057a3cb6 | Ruby | risanto/connect-four | /sandbox.rb | UTF-8 | 115 | 2.65625 | 3 | [] | no_license | arr = [
['O', 'O'],
['X', 'O']
]
results = arr.select.with_index do |val, i|
val[i][1]
end
pp results | true |
9d58e2a98d2a950b63c603338e3a31a912cfd2f3 | Ruby | TomCrypto/Comet | /lib/comet/parser.rb | UTF-8 | 2,721 | 2.703125 | 3 | [
"MIT"
] | permissive | module Comet
class Parser
include Comet::DSL::Helpers
alias inject instance_exec
def software(name, depends:, &block)
raise "software `#{name}' redefined" if @software.key? name
@software[name] = DSL::Software.new(name, depends: depends, &block)
end
def hardware(name, targets:, &bloc... | true |
b225bec5a223520978fead603076fee2c9e13591 | Ruby | Lix311/ruby-oo-self-cash-register-lab-nyc-web-021720 | /lib/cash_register.rb | UTF-8 | 960 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :last_item
items = []
def initialize(empl_discount=nil) #initializer
@total = 0
@discount = empl_discount
@items = []
@last_item = 0
end
def add_item(title, price, quantity=1) #instance method
... | true |
74e98887d0995e3c8276919d9c524e2e7de1fa99 | Ruby | Bor1s/chargen | /app/services/data_extractor_service.rb | UTF-8 | 636 | 2.953125 | 3 | [
"MIT"
] | permissive | class DataExtractorService
def initialize(character_sheet)
@character_sheet = character_sheet
end
def extract
@character_sheet.class.stored_attributes[:data_fields].map do |field_name|
field_name_as_defined_in_sheet = @character_sheet.class.fields_map[field_name]
field_value ... | true |
be0dcb953607b590a51851c7c4db6e4962dbc9dc | Ruby | govaniso/phidgets-ffi | /lib/phidgets-ffi/analog.rb | UTF-8 | 2,885 | 2.5625 | 3 | [] | no_license | module Phidgets
# This class represents a PhidgetAnalog.
class Analog
Klass = Phidgets::FFI::CPhidgetAnalog
include Phidgets::Common
# Collection of analog outputs
# @return [AnalogOutputs]
attr_reader :outputs
attr_reader :attributes
# The attributes of a PhidgetAnalog
def attribut... | true |
6bfe40a67faaf3d24eb0954dee3b0e1bb0afad34 | Ruby | y5f/Projects | /Mini comp /lexer.rb | UTF-8 | 1,467 | 3.25 | 3 | [] | no_license | require 'pp'
Token=Struct.new(:kind,:value,:pos)
class Lexer
attr_accessor :stream
def initialize token_hash
@token_def=token_hash
end
def tokenize str
stream=[]
str.split(/\n/).each_with_index do |str,numline|
stream << tokenize_line(1+numline,str)
end
@stream=stream.flatten
... | true |
f1b5601d747ae9297ed9c7647217690f2e6be3ee | Ruby | jamesdconklin/ORM-Practice | /lib/user.rb | UTF-8 | 1,504 | 2.796875 | 3 | [] | no_license | require_relative 'questionrelation'
require_relative 'model'
class User < ModelBase
attr_reader :id
attr_accessor :f_name, :l_name
def initialize(options)
@id = options['id']
@l_name = options['l_name']
@f_name = options['f_name']
end
def followed_questions
QuestionFollow.followed_question... | true |
ffd6feab492e909e5ac71265ae94fab522f01046 | Ruby | PhilHuangSW/Leetcode | /integer_to_roman.rb | UTF-8 | 3,111 | 4.65625 | 5 | [] | no_license | #################### INTEGER TO ROMAN ####################
# Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
# ```
# Symbol Value
# I 1
# V 5
# X 10
# L 50
# C 100
# D 500
# M 1000
# ```
# For ... | true |
6f18fc8748571203bcd973152972f2fd2229045c | Ruby | redding/sanford-protocol | /lib/sanford-protocol/request.rb | UTF-8 | 1,118 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'sanford-protocol'
module Sanford; end
module Sanford::Protocol
class Request
def self.parse(body)
self.new(body['name'], body['params'])
end
attr_reader :name, :params
def initialize(name, params)
self.validate!(name, params)
@name = name.to_s
@params = params
... | true |
a35e25f8362ca2f98924d68c8dc791300b496544 | Ruby | simplificator/conversions | /test/conversions_test.rb | UTF-8 | 989 | 2.71875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'test_helper'
class ConversionsTest < Test::Unit::TestCase
should 'convert from grams to tons' do
assert_equal 1, 1000000.g_to_t
assert_equal 1.234567, 1234567.g_to_t
assert_equal 0.001, 1000.g_to_t
assert_equal 0.000001, 1.g_to_t
end
should 'convert from grams to kg' do
assert_equ... | true |
d44477487d83a99fff72fbfe7ec82af7e9cbd254 | Ruby | susano/ppsn2012 | /evaluators/pattern_matching_evaluator.rb | UTF-8 | 1,977 | 3.0625 | 3 | [
"MIT"
] | permissive | require 'utils/assert'
class PatternMatchingEvaluator
# ctor
def initialize(patterns)
assert{ !patterns.empty? }
@patterns =
patterns.collect do |p|
p.collect do |v|
if (v == true || v == 1)
true
elsif (v == false || v == 0)
false
else
raise ArgumentError
end
en... | true |
1b9f36a74007e1a1237166a6181cbb6658f12374 | Ruby | littlemighty/test_first | /02_calculator/calculator.rb | UTF-8 | 269 | 3.703125 | 4 | [] | no_license | def add(x, y)
x + y
end
def subtract(x, y)
x - y
end
def sum(x)
x.inject(0){|total, number| total+number}
end
def multiply(*nums)
nums.inject(:*)
end
def power(x, y)
x ** y
end
def factorial(x)
if x < 1
x = 1
else
x * factorial(x-1)
end
end | true |
ef1b2d900a61efee7839f934937d51e53cf7173f | Ruby | atheiman/knife-ansible-inventory | /lib/chef/knife/ansible_inventory.rb | UTF-8 | 2,466 | 2.515625 | 3 | [
"MIT"
] | permissive | class Chef::Knife::AnsibleInventory < Chef::Knife
banner 'knife ansible inventory'
deps do
require 'chef/search/query'
end
option :group_by_attribute,
long: '--group-by-attribute ATTRIBUTE',
description: "Attribute to group hosts by"
option :host_attribute,
long: '--host-attribute ATTRIBUTE... | true |
7f43ae012b934ab8dac61997d13eda48d78c133f | Ruby | genki/wormhole | /test/wormhole_test.rb | UTF-8 | 1,623 | 2.796875 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/test_helper.rb'
require "test/unit"
class WormholeTest < Test::Unit::TestCase
def setup
@result = []
end
def foo
@result << "foo"
data = Wormhole.throw :bar => 'hello'
@result << data[:bar]
@result << "bar"
end
def test_wormhole
Wormhole.catch do
... | true |
88ec28e75638497309414be3e176d89ce3f1a5dd | Ruby | kelseyde/hogwarts | /db/seeds.rb | UTF-8 | 1,906 | 2.71875 | 3 | [] | no_license | require_relative('../models/student')
require_relative('../models/house')
require_relative('sql_runner')
require('pry')
gryffindor = House.new({
"name" => "Gryffindor",
"logo" => "http://vignette1.wikia.nocookie.net/harrypotter/images/8/8e/0.31_Gryffindor_Crest_Transparent.png/revision/latest?cb=20161124074004"})
... | true |
9095e099b0a515934bcf270aa44b021a1118133a | Ruby | svoboda-jan/opal-browser | /opal/browser/window/view.rb | UTF-8 | 225 | 2.59375 | 3 | [] | no_license | module Browser; class Window
class View
def initialize(window)
@window = window
@native = window.to_n
end
def width
`#@native.innerWidth`
end
def height
`#@native.innerHeight`
end
end
end; end
| true |
06fd0debd48ab05be139d98dd24d0250dc00b6a4 | Ruby | jhbadger/scripts | /alertTime | UTF-8 | 218 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
x = Time.now.to_i
diff = 1618033989 - x
hours = diff / 3600
min = diff - hours*3600
secs = diff - 60*min
printf("Currently %d. %d hours %d minutes, %d seconds to target\n", x, hours, min, secs)
| true |
250141d3531eac91b7a4d08865017471313ef091 | Ruby | bbensky/launch_school | /intro_to_ruby/methods/ex1_greeting.rb | UTF-8 | 102 | 3.46875 | 3 | [] | no_license | def greeting(name)
"Hi " + name + "! I hope you're having a swell day!"
end
puts greeting("Brian") | true |
be7db50a792d7879fbf15ed3415e70592a51bd05 | Ruby | CodeMonkeySteve/object-schema | /lib/object_schema/param.rb | UTF-8 | 1,036 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'object_schema/buildable'
# Function Parameter
class ObjectSchema::Param
include ObjectSchema::Buildable
attr_reader :option
def initialize(parent: nil, schema: nil, option: false, &defn)
@required = false
@option = false
super(parent: parent, schema: schema, &defn)
end
def required?
... | true |
1d215e9042840f53c8dcd325bb783a021c84806a | Ruby | greeneca/AdventOfCode2019 | /lib/day14-2.rb | UTF-8 | 2,524 | 3.171875 | 3 | [] | no_license | module P142
class P142
def run(input)
@reactions = {}
input.each do |reaction|
inputs, output = reaction.strip.split("=>")
inputs = inputs.strip.split(",").map{|ingredient| process_ingredient(ingredient)}
output = process_ingredient(output)
@reactions[output[1]] = Reac... | true |
f35a6ff73cd5c99b77370f0b5e5c4902a1d1387f | Ruby | AustinJuliusKim/AustinK_WDI | /08_week/beer_pong_emporium/spec/models/product_spec.rb | UTF-8 | 2,043 | 2.703125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Product, type: :model do
describe "product attributes required?" do
it "returns name" do
product = FactoryGirl.build_stubbed(:product, name: nil)
p product
expect(product).to be_invalid
end
it "returns sku" do
product = FactoryGirl.build_stubbed(:produc... | true |
493fa9e982b6f056511f224fce3a7999ed38a149 | Ruby | VoChrisK/aA-classwork | /W4D1/knights-travails/knightpathfinder.rb | UTF-8 | 2,617 | 3.484375 | 3 | [] | no_license | require_relative "./polytreenode/skeleton/lib/00_tree_node.rb"
class KnightPathFinder
attr_reader :root_node
def self.valid_moves(current_pos)
row, col = current_pos
row >= 0 && row < 8 && col >= 0 && col < 8
end
def initialize(start_pos)
@root_node = PolyTreeNode.new(start_p... | true |
eefcb64e0503e948c42675f61c1ae5cfcba56acd | Ruby | averysoren/ls-core-curriculum | /ruby_book/the_basics/exercise3.rb | UTF-8 | 177 | 3 | 3 | [] | no_license | movies = {fight_club: 1999,
braveheart: 1995,
lucky_number_slevin: 2006}
puts movies[:fight_club]
puts movies[:braveheart]
puts movies[:lucky_number_slevin] | true |
f9a849efe9aacbd3e80b66f2fb1f2633adf31243 | Ruby | EricRicketts/LaunchSchool | /exercises/Ruby/small_problems/easy/one/third_exercise.rb | UTF-8 | 2,719 | 4.125 | 4 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require 'byebug'
class ThirdExercise < Minitest::Test
=begin
List Of Digits
Write a method that takes one argument, a positive integer, and returns a list of the digits in the number.
Examples:
puts digit_list(12345) == [1, 2, 3, 4, 5] # => true
puts digit_li... | true |
3f058e7e0facbe9f52c2903b081cf3d7d82443b9 | Ruby | DrYaR/EXO_RUBY | /exo_20.rb | UTF-8 | 152 | 3.1875 | 3 | [] | no_license | puts "Un nombre s'il vous plait"
print "> "
number = gets.chomp.to_i
i = 0
block = "#"
number.times do puts i = block
block = block + "#"
end
| true |
ebde0575921a57b499d54d541eeecab559915f7f | Ruby | chaplonglau/product_searcher | /service_objects/process_products.rb | UTF-8 | 761 | 2.96875 | 3 | [] | no_license | module ServiceObjects
class ProcessProducts
attr_accessor :products, :store, :value_to_attribute_map
def initialize(products)
@products = products
@store = {}
@value_to_attribute_map = {}
end
def call
products.each do |product|
type = product["product_type"]
... | true |
95d11aaf25d8d60b3d8ab39519bf79efffac9e1f | Ruby | MisterMur/nyc-web-010719 | /06-intro-to-inheritance/lib/dog.rb | UTF-8 | 179 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog < Pet
include ModuleName::InstanceMethods
def initialize(name, num_walks)
@num_walks
super(name)
end
# def walk
# puts "I am walking."
# end
end
| true |
9e8ca4ad4629aaae81141c21bb79bb6b680693f5 | Ruby | lissdy/CODEWARS | /Valid_Parentheses.rb | UTF-8 | 889 | 3.78125 | 4 | [] | no_license | #https://www.codewars.com/kata/52774a314c2333f0a7000688/train/ruby
#MY SOLUTION
def valid_parentheses(string)
return true if string.empty?
left_num = string.size - string.gsub('(','').size
right_num = string.size - string.gsub(')','').size
return false if left_num != right_num
stack = []
string.chars.each... | true |
e317d8b49b5952c28f4ca46e3923845009a8f3e0 | Ruby | sarahabimay/TicTacToe_Gem | /lib/tictactoe/beatable_ai_player.rb | UTF-8 | 436 | 2.984375 | 3 | [] | no_license | require "tictactoe/player"
module TicTacToe
class BeatableAIPlayer
include Player
def initialize(mark, display)
@mark = mark
@display = display
end
def get_next_move(board)
move = randomized_move(board)
display.announce_player_move(mark, move)
move
end
def ran... | true |
18b83db2c88035c6b0c852a0e1f6dfbfead9b74a | Ruby | byzantinist/phase-0-tracks | /ruby/game.rb | UTF-8 | 3,596 | 4.125 | 4 | [] | no_license | # Class declaration
class Game
attr_reader :secret, :length, :secret_array
attr_accessor :guesses, :history, :display
def initialize
# Welcome message
puts "Welcome to Hangunicorn, a game where you need to correctly guess a word or phrase to save the life of an innocent baby unicorn!"
# Player 1: En... | true |
34799192f9c520e8f5fe63b61174fe9739686bef | Ruby | JustinData/GA-WDI-Work | /w04/d03/Erica/crypt.rb | UTF-8 | 98 | 2.53125 | 3 | [] | no_license | def encode(string)
encode = string.tr!('A-Za-z', 'N-ZA-Mn-za-m')
return encode
end
end
| true |
c81b216ecfb077979c3400a3388c7ba226ab220f | Ruby | msmiller/redbus | /backburner/pubsub.rb | UTF-8 | 1,515 | 2.546875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
# @Author: msmiller
# @Date: 2019-09-16 13:24:00
# @Last Modified by: msmiller
# @Last Modified time: 2019-10-31 10:43:43
#
# Copyright (c) Sharp Stone Codewerks / Mark S. Miller
# This is for pub/sub and wait with specific messages
# NOTE: This was the first incarnation. But it wouldn't work well... | true |
00900d1b8a63b7aae7dfe777d654bb615b845d87 | Ruby | Sigwings/Ruby | /bin/RubyLogger.rb | UTF-8 | 1,052 | 2.609375 | 3 | [] | no_license | require_relative 'Directory'
require_relative 'RegistryTools'
class RubyLogger
include Directory
extend RegistryTools
DEFAULT_FILE = "#{ documents_path }\\Ruby Logs\\#{ File.basename( $0, '.*' ) }.log".freeze
attr_accessor :filename, :orig_std_out
def initialize( filename = DEFAULT_FILE )
se... | true |
0481d1a39df0da2c020526e407226c069ac5f819 | Ruby | iain/miniture-ninja | /lib/collada.rb | UTF-8 | 2,451 | 2.796875 | 3 | [] | no_license | class Collada
attr_reader :doc, :filename
def initialize(filename, doc)
@filename = filename
@doc = doc
end
def dir
Pathname(File.dirname(filename))
end
def as_json
{
geometries: geometries,
textures: Hash[textures]
}
end
def geometries
doc.css("instance_geometry... | true |
0ad7d18c27aa9b23987d5a89a5b1ced3f64d71ac | Ruby | enzo9214/E8CP2A1 | /prueba.rb | UTF-8 | 1,737 | 3.296875 | 3 | [] | no_license | alumnos = {}
alumnos_promedios = {}
def abrir_archivo(hash)
data = File.open('notas.csv','r') { |archivo| archivo.readlines }
data = data.map{ |data| data.chomp.split(', ') }
data.each do |info|
hash[info[0]] = [info[1], info[2], info[3], info[4], info[5]]
end
hash.each do |nombre,array_notas|
... | true |
71b8121884e9273fc0559ae521ceac968d4a1a67 | Ruby | tainarareis/DesignPatterns | /strategy/en_us/ruby/celsius_fahrenheit.rb | UTF-8 | 160 | 2.953125 | 3 | [] | no_license | class CelsiusFahrenheit
# Makes the convertion of Celsius to Fahrenheit
def convert(value)
converted_measure = (value * (9.0 / 5.0)) + 32.0
end
end
| true |
3c7a977bd95341fe63d00ca13c9b4c610e87714c | Ruby | AlexanderCode/Practice_Problems | /practice20.rb | UTF-8 | 364 | 4.34375 | 4 | [] | no_license | # practice20.rb
# Write a method that takes a String of digits, and returns the appropriate number as an integer.
def string_to_integer(string)
string.gsub('1', 1).gsub('2', 2).gsub('3', 3).gsub('4', 4).gsub('5', 5).gsub('6', 6).gsub('7', 7).gsub('8', 8).gsub('9', 9).gsub('0', 0)
end
p string_to_integer('4321') #... | true |
930169a0b846c0fecec626a68b05abaf74f2b12c | Ruby | MastersAcademy/ruby-course-2018 | /objects/taras.turchenko/colorized_string.rb | UTF-8 | 318 | 3.265625 | 3 | [] | no_license | class String
COLORS = {
black: 30,
red: 31,
green: 32,
brown: 33,
blue: 34,
magenta: 35,
cyan: 36,
gray: 37
}.freeze
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
COLORS.each do |name, color_code|
define_method(name) { colorize color_code }
end
end
| true |
8a51028b670b44dfcd9ec53279aba5837030e74c | Ruby | joeplyr/pandata | /spec/parser_spec.rb | UTF-8 | 10,940 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'pandata/parser'
describe Pandata::Parser do
let(:liked_albums_html) { read_path('fixtures/ajax/show_more/liked_albums.html') }
let(:liked_tracks_html) { read_path('fixtures/ajax/show_more/mobile/liked_tracks.html') }
let(:liked_artists_html) { read_path('fixtures/ajax/show_mor... | true |
d5c508b9c6f6bcdf829f22536982d9d294ddb262 | Ruby | SellaRafaeli/pickeez | /bl/phones.rb | UTF-8 | 2,399 | 3.359375 | 3 | [] | no_license | module Phones
extend self
def get_phone_country_code(international_number)
Phonelib.parse(international_number).country
end
def international_to_local(international_number)
Phonelib.parse(international_number).national.tr('-','')
end
def local_to_international(local_number,country_code)
Phony... | true |
687e174ec07e292cf0c0e19e732077bb8fe919ea | Ruby | Joe-noh/nippopotamus | /lib/nippopotamus/cli.rb | UTF-8 | 748 | 2.765625 | 3 | [] | no_license | require "nippopotamus"
require "thor"
module Nippopotamus
class CLI < Thor
option :username, type: :string
desc "today", "print today's activities"
def today
config = Nippopotamus::Config.new
config.user_name = options[:username]
activities = Nippopotamus.fetch_activities(config)
... | true |
a8888189d97d779ac2c77b43c2838214841ef4f4 | Ruby | bbensky/pine_ruby_exercises | /chris_pine_ex/ch6_deafgrandma.rb | UTF-8 | 257 | 3.3125 | 3 | [] | no_license | command = ''
while command != 'BYE'
command = gets.chomp
if (command == command.upcase && command != 'BYE')
puts 'NO, NOT SINCE ' + rand(1930..1950).to_s + '!'
else
if command != 'BYE'
puts 'HUH?! SPEAK UP, SONNY!'
end
end
end | true |
63b09bf24e76feef14396a01774b4bf0bf713361 | Ruby | MichaelSRomero/my-each-dumbo-web-career-012819 | /my_each.rb | UTF-8 | 308 | 3.34375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # require 'benchmark'
def my_each(arr)
i = 0
while i < arr.length
yield(arr[i])
i += 1
end
return arr
end
# iterations = 100_000
#
# Benchmark.bm(20) do |bm|
# bm.report("My Each") do
# iterations.times do
# my_each([100, 200, 300, 400]) {|n| n - 100}
# end
# end
# end
| true |
4f91c35600588881072e3c9da86dfbb4b768696a | Ruby | androi7/sei35 | /week5/warmump/luhn.rb | UTF-8 | 1,435 | 4.0625 | 4 | [] | no_license | # class Luhn
#
# def initialize num
# @num = num.to_s
# end
#
# def valid?
# num_arr = @num.split('')
# num_arr = num_arr.reverse.each_with_index.map do |x, i|
# x = x.to_i
# if i % 2 != 0
# x = x * 2 < 10 ? x * 2 : x * 2 - 9
# else
# x = x
# end
# end.reduc... | true |
2412022fb549cb9f610f9169a97e94a520b6df95 | Ruby | ZeroCBR/WeatherPredictor | /lib/prediction_regression.rb | UTF-8 | 5,085 | 3.390625 | 3 | [] | no_license | require 'matrix' # perform the matrix operation
class PredictionRegression
@@TYPE=["linear","polynomial", "exponential", "logarithmic"]
# read the arguments from the command line and jump to the specified regression
def initialize x, y, period
@x=x
@y=y
@periods=[]
periodToArray(period)
@expectY=Array.new... | true |
53054b1771fef72a10160b3c739f8edcb9045213 | Ruby | codecell/algo | /queue.rb | UTF-8 | 1,128 | 4.0625 | 4 | [] | no_license | # Start with your code from LinkedList challenge.
class Node
attr_accessor :value, :next_node
def initialize(value, next_node = nil)
@value = value
@next_node = next_node
end
end
class Queue
def initialize(front = nil, back = nil)
@front = front
@back = back
end
def add(number)
n... | true |
75619b333b8ea659e543aa5c1bfdff30c75f95a0 | Ruby | Macaroni2629/Launch-School | /120_object_oriented_programming/oop_book_exercises/1_the_object_model/ex_1.rb | UTF-8 | 385 | 4.1875 | 4 | [] | no_license | # How do we create an object in Ruby?
# Give an example of the creation of an object.
class Cat
end
socks = Cat.new
=begin
We create an object by defining a class using the 'class' keyword and the reserved word 'end'.
We then instantiate the object and named it 'socks' in this case.
We create an 'instance' o... | true |
15bf29955acd34f7f627ff5e0df3465efb3e03dc | Ruby | KatKmiotek/weekend_homework_week02 | /song.rb | UTF-8 | 118 | 2.703125 | 3 | [] | no_license | class Song
attr_reader :title, :artist
def initialize(title, artist)
@title = title
@artist = artist
end
end
| true |
4b36ae9ae8a03f569e3949b2d4d0b13b67bb9eb4 | Ruby | puppetlabs/r10k | /spec/unit/util/setopts_spec.rb | UTF-8 | 2,334 | 2.65625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
require 'r10k/util/setopts'
describe R10K::Util::Setopts do
let(:klass) do
Class.new do
include R10K::Util::Setopts
attr_reader :valid, :alsovalid, :truthyvalid
def initialize(opts = {})
setopts(opts, {
:valid => :self,
:duplicate => :valid,
... | true |
2c45a538bb0388cd2e685e6915c2c427e0a7dc5a | Ruby | sergeypedan/integral-text-helpers | /lib/integral/text_helpers/phone.rb | UTF-8 | 2,264 | 2.90625 | 3 | [] | no_license | # frozen_string_literal: true
module Integral
module TextHelpers
module PhoneHelper
require "active_support/number_helper/number_converter"
require "active_support/number_helper/number_to_phone_converter"
# Uses Rails `number_to_phone` helper
# https://apidock.com/rails/v5.2.3/ActionVie... | true |
1d257780d9368c68b61e237a61fa46f91e5bd590 | Ruby | desanlee/chifan | /app/models/gamblegame.rb | UTF-8 | 915 | 2.828125 | 3 | [] | no_license | class Gamblegame < ActiveRecord::Base
attr_accessible :description, :options, :result, :user_id
belongs_to :user
has_many :bets, foreign_key: "gamble_id"
def Gamblegame.currentgambles
cg = Array.new
Gamblegame.all.each do |g|
if g.result == nil then
cg << g
end
end
return cg
end
def Gam... | true |
af48b8ce26509e6b9c88695d5b199b1711c973ce | Ruby | michaelherold/benchmark-memory | /lib/benchmark/memory/job.rb | UTF-8 | 3,778 | 2.921875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'forwardable'
require 'benchmark/memory/job/task'
require 'benchmark/memory/job/io_output'
require 'benchmark/memory/job/null_output'
require 'benchmark/memory/held_results'
require 'benchmark/memory/report'
require 'benchmark/memory/report/comparator'
module Benchmark
module M... | true |
26c6e2839167ab1c8a1c3e8f0d87930ae8e87e44 | Ruby | sibprogrammer/specscan | /test/unit/mobile_operator_test.rb | UTF-8 | 1,414 | 2.5625 | 3 | [] | no_license | require 'test_helper'
class MobileOperatorTest < ActiveSupport::TestCase
test "should not save mobile operator without required attributes" do
mobile_operator = MobileOperator.new
assert !mobile_operator.save
end
test "valid mobile operator" do
mobile_operator = MobileOperator.new(:title => 'Test',... | true |
8917f02ff34195884d47f10d49ec47dca235371d | Ruby | SecretSurfSpot/intro_to_the_web | /app.rb | UTF-8 | 504 | 2.5625 | 3 | [] | no_license | require 'sinatra'
set :session_secret, 'super secret'
get('/') {"HELO GOODBYE"}
get('/secret') { 'Here is a secret page'}
get('/apple') { 'Here is yet another page'}
get('/pear') { 'Today is monday'}
get('/orange') { 'Tomorrow is Tuesday'}
get('/blueberry') { 'The day after tomorrow is Wednesday'}
get('/random-cat') ... | true |
efe95e9d9c3a36e780b664f083b63a4a45c22128 | Ruby | 140ch204/14_MVC_gossip | /lib/controller.rb | UTF-8 | 514 | 2.671875 | 3 | [] | no_license | # 2_ Contrôlé par le routeur
require './lib/gossip'
require './lib/view'
class Controller
def initialize()
@view = View.new
end
def perform()
end
def create_gossip()
params = @view.create_gossip
gossip = Gossip.new(params[:content], params[:author])
puts "Gossip créé"
... | true |
0ed8fa3a8a31c0e6fc0ca2c07dd34d056f449231 | Ruby | tolidevs/london-web-120919 | /14-rails-associations/app/models/film.rb | UTF-8 | 312 | 2.671875 | 3 | [] | no_license | class Film < ApplicationRecord
has_many :reviews
has_many :users, through: :reviews
def average_rating
if self.reviews.size == 0
return 'N/A'
end
total = self.reviews.reduce(0){|total, review| total + review.rating }
total / self.reviews.size
end
end
| true |
799e765cc60e086c798425e4895e0819f83f1e66 | Ruby | ChristianTracy/ejercicio_26_9 | /ejercicio1/Reptiles/Reptiles.rb | UTF-8 | 539 | 2.8125 | 3 | [] | no_license | require_relative '../Animal.rb' #incluyo el archivo con la clase padre
#-------------------------
class Reptiles < Animal; end
#-------------------------
#-------------------------
class Cocodrilo < Reptiles
include Caminar
include Nadar
end
#-------------------------
#-------------------------
class Boa < Reptile... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.