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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
7ef04c6a695a13b60dee8e68214f9eb99153fd54 | Ruby | IanVaughan/loggie | /lib/loggie/configuration.rb | UTF-8 | 1,000 | 2.515625 | 3 | [
"MIT"
] | permissive | module Loggie
class << self
attr_accessor :configuration
end
READ_TOKEN = ENV['READ_TOKEN']
LOG_FILES = ENV['LOG_FILES'].split(",")
def self.configure
self.configuration ||= Configuration.new
yield(configuration) if block_given?
end
class Configuration
MAX_RETRY_DELEY_SECONDS = 20.0 # m... | true |
2b5b4fec530d5c00047d4c50c7461c6dc90a686b | Ruby | sphynx79/Remit_Linee | /script_usati/read_generators.rb | UTF-8 | 2,230 | 2.65625 | 3 | [] | no_license | require 'ap'
require 'pry'
require 'mongo'
MONGO_ADRESS = '127.0.0.1'
MONGO_PORT = '27017'
MONGO_DB = 'transmission'
Mongo::Logger.logger.level = ::Logger::FATAL
class Database
attr_accessor :client, :docs
def initialize
@client = connect_db
@coll_centrali = @client[:centrali]
end
#
#... | true |
9d9904c8bccbdf90d398dc10faedd5860cc0a272 | Ruby | rarachocolate/dragon_quest2 | /character.rb | UTF-8 | 288 | 3.296875 | 3 | [] | no_license | class Character
attr_reader :name, :hp, :defense
attr_writer :hp
def initialize(name: , hp: 100, offense: 50, defense: 40)
@name = name
@hp = hp
@offense = offense
@defense = defense
end
def calculate_damage(enemy)
@offense - enemy.defense / 2
end
end
| true |
f4d085224953aef553691d1500c4aa0fc606f0ba | Ruby | grandsoleil/ruby_thp | /exo_12.rb | UTF-8 | 126 | 3.578125 | 4 | [] | no_license | puts "Donne moi un nombre ?"
nombre=gets
compteur = 1
while compteur < nombre.to_i + 1
puts compteur.to_s
compteur += 1
end | true |
c3a3a708c4842c4d42f4f05cfdd14c8df5ef85ee | Ruby | simpsonjulian/djbt | /lib/lant.rb | UTF-8 | 1,599 | 2.71875 | 3 | [] | no_license | require 'lib/project'
class Lant
attr_writer :file, :basedir, :display_properties
def parse(file)
project = Project.new(file)
@project_basedir = project.get_basedir()
name = project.get_name()
properties = project.properties()
targets = project.targets()
nested_props = project.... | true |
1652cb5c6fa5b058de8ba074b49c032df6ee5cd4 | Ruby | timostrating/ProjectEuler | /ruby/Problem054.rb | UTF-8 | 3,862 | 4.03125 | 4 | [] | no_license | # In the card game poker, a hand consists of five cards and are ranked, from
# lowest to highest, in the following way:
# * High Card: Highest value card.
# * One Pair: Two cards of the same value.
# * Two Pairs: Two different pairs.
# * Three of a Kind: Three cards of the same value.
# * Straight: All cards... | true |
ff8430707290f4e6079e183de3d209d9d2c4c5e7 | Ruby | AustinRhoads/ruby-music-library-cli-online-web-sp-000 | /lib/music_library_controller.rb | UTF-8 | 2,382 | 3.6875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_all 'lib'
require 'pry'
class MusicLibraryController
include Sortable
#extend Findable
attr_accessor :path
def initialize(path = './db/mp3s')
@path = path
@library = MusicImporter.new(@path)
@library.import
end
def call
puts "Welcome to your music library!"
puts "To list all of your songs, enter 'l... | true |
96e8a6070864065f5e959145f2d07dd257b603f3 | Ruby | matsumonkie/Arch | /spec/operations/operation_spec.rb | UTF-8 | 760 | 2.65625 | 3 | [] | no_license | require "rails_helper"
RSpec.describe Operation do
def nb_methods(klass)
(klass.public_methods - Object.public_methods).size
end
it 'respond_to anything' do
expect(UserOp.respond_to?(:index)).to be true
end
it 'dynamically create method' do
expect(nb_methods(SpecOp)).to eq(nb_methods(Operation... | true |
36865b27fa4443ba64a997ddec1ec025096d0e76 | Ruby | KatieLars/RubySandbox | /fibonacci.rb | UTF-8 | 219 | 3.40625 | 3 | [] | no_license | require 'pry'
def fib(n) #n is an index
i = 2
rel_num = {0 => 1, 1 =>1}
until i > n-1
new_num = rel_num[0] + rel_num[1]
rel_num[0] = rel_num[1]
rel_num[1] = new_num
i += 1
end
puts rel_num[1]
end
| true |
e960345981e7ae71e2605a5e3298975454847fe4 | Ruby | brentmartin/TIY-Blog | /app/controllers/posts_controller.rb | UTF-8 | 1,639 | 2.578125 | 3 | [] | no_license | class PostsController < ApplicationController
def index #GET
@posts = App.posts
render_template 'posts/index.html.erb'
end
def show #GET
post = find_post_by_id
if post
if request[:format] == "json"
render post.to_json
else
@post = post
render_template 'pos... | true |
7681308f128601c1406455f5effd6ff91bd6001e | Ruby | johnjvaughn/ls_course101 | /SmallProblems/Medium2/tri-angles.rb | UTF-8 | 485 | 3.640625 | 4 | [] | no_license | TRIANGLE_TYPES = [:right, :acute, :obtuse, :invalid]
def triangle(angle_A, angle_B, angle_C)
angles = [angle_A, angle_B, angle_C]
case
when angles.sum != 180 || angles.min <= 0
:invalid
when angles.include?(90)
:right
when angles.max > 90
:obtuse
else
:acute
end
end
puts triangle(60, 7... | true |
fd5a3d1140a396ca013b59e7a6c3a683cd58beb8 | Ruby | lamjay415/AAClasswork | /W4D5/d5/two_sum.rb | UTF-8 | 1,007 | 3.984375 | 4 | [] | no_license | #n!
#n^2
def bad_two_sum?(arr, target_sum)
perm = arr.permutation(2).to_a
sum = perm.map{|el| el.sum}
sum.include?(target_sum)
end
#nlogn
#n
def okay_two_sum?(arr, target_sum)
sorted = arr.sort
sorted.each do |num|
result = target_sum - num
return true if num != result &... | true |
89ac38a3a30e1cddd6a850eacd52bc0e756f1907 | Ruby | pawneetdev/camstore_api | /test/models/category_test.rb | UTF-8 | 953 | 2.5625 | 3 | [] | no_license | require 'test_helper'
class CategoryTest < ActiveSupport::TestCase
test "name must be present" do
category = Category.new
category.category_type = "point and shoot"
category.model = 2019
assert_not category.valid?
end
test "category_type must be present" do
category = Category.new
category.name = "ni... | true |
b169a0eafcd77ad744afa6a97839ac6c018b7d01 | Ruby | juniorz/mars_rovers | /test/rover_test.rb | UTF-8 | 1,465 | 3.0625 | 3 | [] | no_license | require 'minitest/autorun'
require 'rover'
require 'plateau'
class RoverTest < MiniTest::Unit::TestCase
def test_that_it_has_heading
rover = Rover.new
assert_raises ArgumentError do
rover.heading = 'Z'
end
rover.heading = 'N'
assert_equal 'N', rover.heading
end
def test_that_it_can_... | true |
1da39662a06b4dcf0d135429d8e6532d251a8c1d | Ruby | maestrodev/ruote-stomp | /lib/ruote-stomp/participant.rb | UTF-8 | 6,196 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | require 'ruote/part/local_participant'
require 'ruote-stomp'
module RuoteStomp
#
# = Stomp Participants
#
# The RuoteStomp::ParticipantProxy allows you to send workitems (serialized as
# JSON) or messages to any Stomp queues right from the process
# definition. When combined with the RuoteStomp::Receiver y... | true |
73a74f34a0b0bbb95ce50cceef6d19b36f052700 | Ruby | adambird/schedulicon | /lib/schedulicon/schedule.rb | UTF-8 | 2,257 | 3.0625 | 3 | [] | no_license | # Public: Describes a schedule in a portable fashion
#
require 'time'
require 'date'
module Schedulicon
class Schedule
FREQUENCIES = [:every, :first, :second, :third, :fourth, :last]
attr_accessor :frequency, :day_of_week, :start_at, :end_on
def initialize(attrs={})
@start_at = Time.xmlschema(att... | true |
b1feeb09665a629b276f61bbca55ebf086c13a14 | Ruby | gor-sg/algorithms | /strings_2_shuffle.rb | UTF-8 | 165 | 2.953125 | 3 | [] | no_license | s = '012345678'
m = x.length - 1 # 8
p s
0.upto(m - 1) do |i|
j = i + rand(m - i) + 1
s[i], s[j] = s[j], s[i]
end
p s
# m|i|j
# 8,0,1..8
# 8,1,2..8
# 8,2,3..8
| true |
90669105192aaad9fd8579d1c3194a59d6fc69bc | Ruby | kmdsbng/rmaybe | /spec/core/basic_usage_spec.rb | UTF-8 | 496 | 2.78125 | 3 | [
"MIT"
] | permissive | # -*- encoding: utf-8 -*-
require 'spec_helper'
require 'rmaybe'
describe 'maybe' do
it 'end method returns actual value' do
"hoge".maybe.upcase[0..2].end.should eq('HOG')
end
it 'nil.any_method return nil' do
[0].maybe[1].next.end.should eq(nil)
end
it 'throws no method error' do
lambda {
... | true |
ffce130a4db5b2702e6838aeb261ff91939b28ab | Ruby | azhang9328/ruby-oo-practice-flatiron-mifflin-exercise-seattle-web-120919 | /lib/Employee.rb | UTF-8 | 817 | 3.1875 | 3 | [] | no_license | class Employee
attr_reader :name, :salary, :manager
@@all = []
def initialize(name, salary, manager)
@name = name
@salary = salary
@manager = manager
save
end
def self.all
@@all
end
def save
@@all.push(self)
end
def manager_name
... | true |
2bb120cf796b6a1664189f099cb2b8904107dcae | Ruby | rachandiwala/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 931 | 3.5625 | 4 | [] | no_license |
def echo(a)
"#{a}"
end
echo("hello")
def shout(b)
"#{b}".upcase
end
shout("hello")
# The below codes are working fine, however not passing through the rake test
def repeat (say, how_many = 2)
("#{say} " * how_many).strip
end
#str will return number of letters from num string
def start_of_word (s... | true |
4403cd3b079afbcad1a136396759fa33da359c8a | Ruby | atecdeveloper/ruby_lessons | /variables/age.rb | UTF-8 | 341 | 4.5 | 4 | [] | no_license | #gets example
puts "How old are you?"
age = gets.chomp.to_i #convert the input string to integer
puts "In 10 years you will be:\n" + (age + 10).to_s #convert the integer value to string
puts "In 20 years you will be:\n" + (age + 20).to_s
puts "In 30 years you will be:\n" + (age + 30).to_s
puts "In 40 years you will be:... | true |
16cf956fae8c8515b79677133b3bbc96cab0d14b | Ruby | JobPods/ruby-cb-api | /lib/cb/clients/application_api.rb | UTF-8 | 2,636 | 2.515625 | 3 | [] | no_license | require 'json'
module Cb
class ApplicationApi
#############################################################
## Get an application for a job
## Takes in either a Cb::CbJob, or a string (which should contain a did)
##
## For detailed information around this API please visit:
## http://api.career... | true |
c6f1751d78b57f5b63eb44699ae5f6539dc1f589 | Ruby | pkim050/ruby-collaborating-objects-lab-online-web-ft-021119 | /lib/song.rb | UTF-8 | 550 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :new_by_filename, :artist, :name
# attr_reader :name
def initialize(name)
@name = name
end
# def name=(name)
# @name = name
# end
# def artist=(artist_obj)
# @artist = artist_obj
# end
def new_by_filename(filename)
@new_by_filename = filename
end
... | true |
6f0bb51b0867891a42d73a1b57a2286a8c0d39b6 | Ruby | SpeciesFileGroup/taxonworks | /lib/application_enumeration.rb | UTF-8 | 3,320 | 2.671875 | 3 | [
"NCSA",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | Dir[Rails.root.to_s + '/app/models/*.rb'].each { |file| require_dependency file }
# Methods for enumerating models, tables, columns etc.
#
# !! If you think that a method belongs here chances are it already exists in a Rails extension.
#
# Note the use of Module.nesting (http://urbanautomaton.com/blog/2013/08/27/rails... | true |
aeaed2ca4c43e65557433ec7bb36ea0718a23960 | Ruby | BrandyMint/model-pretender | /lib/model_pretender.rb | UTF-8 | 1,422 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'model_pretender/version'
require 'active_record'
class ModelPretender
include ActiveModel::Model
include ActiveModel::Validations
include ActiveModel::Serialization
def self.attr_accessor *attrs
attrs.each do |attr|
@attribute_keys ||= []
@attribute_keys << attr.to_s
end
super
... | true |
fe237dde83b8ce7f96e72307baf8144fe332a2d3 | Ruby | os6sense/checkout_kata | /spec/promotional_rules_spec.rb | UTF-8 | 1,311 | 2.53125 | 3 | [] | no_license | require_relative '../lib/promotional_rules.rb'
describe PromotionalRule do
let(:probe) { -> {} }
describe '#initialize' do
let(:trigger) { -> {} }
context 'when no block is provided' do
it 'raises an ArgumentError' do
expect { described_class.new(trigger) }.to raise_error ArgumentError
... | true |
74ce6135966536a56709525c4076942953d63231 | Ruby | rhomobile/rhodes | /lib/framework/unicode_normalize.rb | UTF-8 | 3,234 | 3.09375 | 3 | [
"MIT"
] | permissive | # coding: utf-8
# frozen_string_literal: false
# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
# additions to class String for Unicode normalization
class String
# === Unicode Normalization
#
# :call-seq:
# str.unicode_normalize(form=:nfc)
#
# Returns a normalized form of +... | true |
fccc54d253d4c895bd4e8a1a789f05b9c843cef5 | Ruby | MikeAllison/tealeaf_ruby | /11_workbook/advanced/quiz_1/06.rb | UTF-8 | 286 | 3.734375 | 4 | [] | no_license | class String
def map_words!
punctuation = self.slice!(-1) if self.end_with?(".", "?", "!")
words = self.split
words.each do |word|
word.reverse!
end
result = words.join(" ").concat(punctuation)
end
end
str = "Herman Munster is a BIG BIG man."
p str.map_words!
| true |
d8e6458060daf7551d79c8c568559f25332b8ca0 | Ruby | IIC2173-2015-2-Grupo2/news-getter | /Postman.rb | UTF-8 | 884 | 3.15625 | 3 | [] | no_license | require 'rubygems'
require 'httparty'
require 'json'
# this class send (posts) the news to the analyzer
class Postman
include HTTParty
base_uri "http://#{ENV['URI_ANALYZER']}"
attr_accessor :news
attr_accessor :url
def initialize
@url = ENV["URL_ANALYZER"]
@url = "/" if @url == ""
@@news = []
end
# add t... | true |
8557876dca3fb7ac0362d436b7dfad1ef93c4d87 | Ruby | kimono-k/Waifu-store | /temp.rb | UTF-8 | 153 | 3.375 | 3 | [
"MIT"
] | permissive | if_condition = false
elsif_condition = true
if if_condition
puts "if clause"
elsif elsif_condition
puts "elsif clause"
else
puts "else clause"
end | true |
2a7df05c93d46f89792bc241b82988a89f7b3ff7 | Ruby | evdokimov-r/thinknetica | /les2/ideal_weight.rb | UTF-8 | 693 | 3.5 | 4 | [] | no_license | puts 'Это программа - узнай свой идеальный вес' #поменял на одинарные кавычки
puts 'Введите Ваше имя' #поменял на одинарные кавычки
first_name = gets.chomp
puts 'Введите свой рост' #поменял на одинарные кавычки
user_height = gets.chomp.to_i #перевел сразу в integer
if user_height > 110
puts "#{first_name.capitalize},... | true |
119a9cd55dd73c7a6f0be67dca6fa75c674e608b | Ruby | ToniRib/black_thursday | /spec/merchant_repository_spec.rb | UTF-8 | 2,502 | 2.953125 | 3 | [] | no_license | require 'spec_helper'
require './lib/merchant_repository'
require './lib/merchant'
require './lib/item'
describe MerchantRepository do
let(:merchants) do
[
Merchant.new(id: 1, name: 'Etsy'),
Merchant.new(id: 2, name: 'Target'),
]
end
subject { described_class.new(merchants) }
describe '#a... | true |
82bb2d04455069bbeca9181b570224c1f2c90f28 | Ruby | cgardn/learn_ruby | /05_book_titles/book.rb | UTF-8 | 476 | 3.515625 | 4 | [] | no_license | class Book
attr_reader :title
def title=(t)
@title = titleFormat(t)
end
def titleFormat(t)
no_list = ['a','an','the','and','in','of','over','at']
t = t.split
t[0] = t[0].capitalize
out = t[1,t.length].map do |x|
if (!no_list.include?(x))
... | true |
ef1f473bf048c001680d2dfc77f26991196618c5 | Ruby | NicolasJJensen/Terminal-RPG | /Levels/level2.rb | UTF-8 | 911 | 2.796875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'os'
require_relative '../Core/level'
require_relative '../Core/GameObjects/Terrain/water'
require_relative '../Core/GameObjects/Terrain/submerged_rock_class'
require_relative '../Core/GameObjects/Misc/ripple'
sound_proc = proc do
if OS.windows?
require 'win32/sound'
... | true |
a8096fe4abe09b44697e5948be47e1eb667f6308 | Ruby | aaronsw/commitron | /lib/commitron/build_checker.rb | UTF-8 | 959 | 2.59375 | 3 | [
"MIT"
] | permissive | module Commitron
class BuildChecker
def initialize(rof_user, rof_password)
@rof_user = rof_user
@rof_password = rof_password
@previous_build_state = {}
end
def run
driver = Selenium::WebDriver.for :chrome
rof = RailsOnFire.new driver, @rof_user, @rof_password
rof.log_... | true |
660d4d964c8c5889bb7cc669492e0dfe8c05411e | Ruby | wenchonglai/aA_Homework | /W3D5/ADTs/map.rb | UTF-8 | 1,054 | 3.53125 | 4 | [] | no_license | class Map
def initialize(arr_2d = [])
@data = []
arr_2d.map{|pair| self.set(*pair)}
end
def set(key, val)
i = index_of(key)
if i.nil?
@data << [key, val]
else
@data[i][1] = val
end
end
def get(key)
i = index_of(key)
@data[i][1] unless i.nil?
end
def delete(ke... | true |
1ab0017ed99799174de2de2460e44367ff2efcf6 | Ruby | handlez36/CodingChallenges | /AdvCh2/palindrome/palindrome.rb | UTF-8 | 207 | 3.46875 | 3 | [] | no_license | class String
def palindrome?
return true if self == nil || self == ""
orig_str = self.gsub(/[^a-zA-Z]/, '')
rev_str = orig_str.chars.reverse.join
orig_str == rev_str
end
end | true |
a5c1eba6c6e6a45203082878f37d622c6b57fe23 | Ruby | bhollan/oxford-comma-v-000 | /lib/oxford_comma.rb | UTF-8 | 182 | 3 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def oxford_comma(array)
if (array.length>1)
array[-1] = "and ".concat(array.last)
end
if (array.length == 2)
return array.join(" ")
end
return array.join(", ")
end
| true |
8780a89343b40a301b118ab83dc21cd92b2a77b1 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/577bc50584684c84821ceb8026cd0ac0.rb | UTF-8 | 580 | 3.921875 | 4 | [] | no_license | class Bob
def hey(phrase)
@phrase = phrase
case
when yelling?
'Woah, chill out!'
when question?
'Sure.'
when silence?
'Fine. Be that way!'
else
'Whatever.'
end
end
private
def yelling?
is_upcased? && !string_of_numbers?
end
def question?
@phras... | true |
8d4287487d03592e3a6e6270819f1d5380540d98 | Ruby | dbelling/ice_and_fire_api | /lib/ice_and_fire_api/book.rb | UTF-8 | 1,261 | 2.828125 | 3 | [
"MIT"
] | permissive | module IceAndFireApi
class Book
attr_reader :url, :name, :isbn, :authors,
:numberOfPages, :publisher, :country,
:mediaType, :released, :characters, :povCharacters
def initialize(attributes)
@url = attributes['url']
@name = attributes['name']
@isbn = attribute... | true |
50719f087bc0d53b390580d12b74836ab3b5d09c | Ruby | cie/rubylog | /lib/rubylog/builtins/term.rb | UTF-8 | 1,223 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | rubylog do
class << primitives_for Rubylog::Term
# Unifies +a+ with +b+. Both can be a proc, which is then called and the result
# is taken.
def is a,b
a = a.rubylog_resolve_function
b = b.rubylog_resolve_function
a.rubylog_unify(b) { yield }
end
# Unifies +a+ with +b+. Fails i... | true |
80606073da2011fb51d189d1d258ce203f42cde8 | Ruby | bonyiii/fibza_role | /lib/fibza_role/user_additions.rb | UTF-8 | 1,761 | 2.8125 | 3 | [
"MIT"
] | permissive | module FibzaRole
# Should be included in current_user model class.
# Process authorization for current_user.
module UserAdditions
module ClassMethods
end
def self.inlcuded(base)
base.class_eval do
end
base.extend(ClassMethods)
end
# If a perm... | true |
1a4de9328aab5e2e4990fd47ac336d6bc61e5023 | Ruby | maryhowell/Algorithm-projects | /Binary_search_tree/solution/lib/interview_questions.rb | UTF-8 | 2,042 | 3.875 | 4 | [] | no_license | # Post Order Traversal:
def post_order(left, light, root)
end
# Pre Order Traversal:
def pre_order(root, left, right)
end
# if you want to do the interview questions you change the ordering of
# this to make that it does post and pre order
def in_order_traversal(tree_node = @root, arr = [])
# ... | true |
418367dd7a0b4e9d76f2947339693a288fa7a4f4 | Ruby | yurimann/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 128 | 3.390625 | 3 | [] | no_license | def add(x, y)
x + y
end
def subtract(x, y)
x - y
end
def sum(x)
if x == []
x = 0
else
x.inject(:+)
end
end
| true |
f9452260b758f0468956cdb3ec72ccb6acd862da | Ruby | vachanda/calculator | /lib/calc/parser.rb | UTF-8 | 1,110 | 3.03125 | 3 | [] | no_license | # to parse commands from command line into array
require_relative '../calc'
class Calc::Parser
$command_store = []
def initialize(command)
@command = command
end
def split_command
@command.split(' ')
end
def decision_maker
arg_array = split_command
return Calc::AddCommand.new(arg_arra... | true |
8f469984e5cf65548c07734c8c79e18f7c8d6a67 | Ruby | mongodb/mongoid | /lib/mongoid/association/constrainable.rb | UTF-8 | 1,168 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# rubocop:todo all
module Mongoid
module Association
# Used for converting foreign key values to the correct type based on the
# types of ids that the document stores.
module Constrainable
# Convert the supplied object to the appropriate type to set as the
# fo... | true |
009a2ed98e4b18372bbcec62297362ed33d8cd3a | Ruby | takeller/credit_check | /lib/credit_check.rb | UTF-8 | 1,543 | 4 | 4 | [] | no_license | require 'pry'
class CreditCard
attr_reader :card_number, :limit
# initialize card_number and limit as strings
def initialize(card_number, limit)
@card_number = card_number
@limit = limit
end
def is_valid?
luhn(@card_number)
end
def last_four
@card_number[-4..-1]
end
end
... | true |
f16ddb5d4b5bf9f6638ca69237845192908fbc06 | Ruby | chenyan19209219/gitlab-ce | /app/finders/milestones_finder.rb | UTF-8 | 1,490 | 2.625 | 3 | [
"MIT",
"CC-BY-SA-4.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
# Search for milestones
#
# params - Hash
# project_ids: Array of project ids or single project id or ActiveRecord relation.
# group_ids: Array of group ids or single group id or ActiveRecord relation.
# order - Orders by field default due date asc.
# title - filter by title.
# ... | true |
f359839828e9e5e5352f5cb8f24332bfc9b93866 | Ruby | gregors/boilerpipe-ruby | /lib/boilerpipe/filters/min_words_filter.rb | UTF-8 | 318 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | # Keeps only those content blocks which contain at least k words.
module Boilerpipe::Filters
class MinWordsFilter
def self.process(min_words, doc)
doc.text_blocks.each do |tb|
next if tb.is_not_content?
tb.content = false if tb.num_words < min_words
end
doc
end
end
end
| true |
510e854a325bf349eeae8b510e3751b3b2978e7f | Ruby | agsutter/101-109_small_problems | /medium1/lights.rb | UTF-8 | 1,706 | 4.4375 | 4 | [] | no_license | # You have a bank of switches before you, numbered from 1 to n. Each
# switch is connected to exactly one light that is initially off. You
# walk down the row of switches and toggle every one of them. You go
# back to the beginning, and on this second pass, you toggle switches
# 2, 4, 6, and so on. On the third pass, y... | true |
6ef7dc0e36cf2ee57256e5ed1e3869af0d57fca8 | Ruby | Vgoylo/shapes | /src/shape.rb | UTF-8 | 220 | 3.21875 | 3 | [] | no_license | # frozen_string_literal: true
require 'colorize'
class Shape
attr_reader :color
def initialize(color)
@color = color
end
def say(color)
"my color is #{color}".send(color)
end
def square; end
end
| true |
b22582af2cc2f1fcba67b7d7679de77cda72c42d | Ruby | maximderbin/rom-repository | /lib/rom/repository/struct_builder.rb | UTF-8 | 1,536 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'dry/core/inflector'
require 'dry/core/cache'
require 'dry/core/class_builder'
require 'dry/struct'
require 'rom/struct'
require 'rom/repository/struct_attributes'
require 'rom/schema/type'
module ROM
class Repository
# @api private
class StructBuilder
extend Dry::Core::Cache
def call(*... | true |
26ba97c390480963cd7869daa17586af5133d631 | Ruby | jhbadger/scripts | /genePair | UTF-8 | 548 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'optparse'
require 'Btab'
ARGV.options {|opts|
opts.banner << " btab-file"
begin
opts.parse!
rescue
STDERR.puts $!.message
STDERR.puts opts
exit(1)
end
if (ARGV.size != 1)
STDERR.puts opts
exit(1)
end
}
btab, rest = ARGV
bins = [0, 0, 0, 0, 0, 0, 0, 0,... | true |
e583aca58b45c3af8e2fb962b287dbe014ea13db | Ruby | RFSS88/Homework | /W3D5/Map.rb | UTF-8 | 629 | 3.140625 | 3 | [] | no_license | class Map
def initialize
@complete = []
end
def set(key, val)
pair_idx = @complete.index { |pair| pair[0] == key }
if pair_idx_index
@complete[pair_idx][1] = val
else
@complete.push([key, val])
end
val
# unless @pair.include?(... | true |
938597dbf87a56d4e7ed1407a520f4c2cfbf5d44 | Ruby | mixelpixel/POODR | /ch7/7d.rb | UTF-8 | 577 | 2.6875 | 3 | [] | no_license | =begin
http://pdf.th7.cn/down/files/1502/Practical%20Object-Oriented%20Design%20in%20Ruby.pdf
CHAPTER 7 - Sharing Role Behavior with Modules, Extracting the Abstraction pg.151-152
=end
require_relative '7c.rb' # <-- module Schedulable
require_relative '7a.rb' # <-- class Schedule
class Bicycle
include Schedulabl... | true |
4617c7344f8e41f8f38785c33147eeaea2b07fbf | Ruby | jules2689/personal_stats | /slack_stats/grapher.rb | UTF-8 | 1,968 | 2.828125 | 3 | [] | no_license | require 'time'
require 'json'
module SlackStats
class Grapher
def initialize(title)
@title = title
end
def graph(data, group_by)
values = if group_by.is_a?(Proc)
group_by.call(labels)
else
default_graph(data, group_by)
end
data = { labels: labels, datasets: ... | true |
283994ba28edd8a69271a3f427404cc911b8008d | Ruby | robinwebber/jungle-rails | /spec/models/product_spec.rb | UTF-8 | 1,026 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Product, type: :model do
describe 'Validations' do
cat = Category.new(name: "fun")
subject{described_class.new(name: "testName", price_cents: 1105, quantity: 10, category: cat)}
it "is not valid if fields are blank" do
expect(subject).to be_valid
end
i... | true |
4f14f06195f67ae0e26e59b307086069e15588d1 | Ruby | pb-pravin/comm_offers | /app/searchers/search_results.rb | UTF-8 | 564 | 2.71875 | 3 | [] | no_license | class SearchResults
attr_reader :offers, :category_facets, :origin, :directories
def initialize(offers, category_facets, origin, directories)
@offers, @category_facets, @origin, @directories = offers, category_facets, origin, directories
end
def add_offers(offers)
@offers.concat(offers)
@offer... | true |
5b73e096d5b664814c12a4cbd02b7bd7772e2125 | Ruby | darkn3rd/oop-tut | /ruby/relocated/c01.construct/demo.rb | UTF-8 | 722 | 3.953125 | 4 | [] | no_license | #!/usr/bin/ruby
require 'Person' # include Person.rb
puts "Creating two objects:\n\n"
# create two objects
captain = Person.new # instantiate new object
officer = Person.new # instantiate new object
# initialize data through mutator (set)
captain.setName "Jean-Luc" # call mutator
officer.se... | true |
2ba2ea9f3d5c91787017630fc70bce6d19aa4941 | Ruby | danielws/learnruby | /ex31_ec.rb | UTF-8 | 1,803 | 4.125 | 4 | [] | no_license | # Exercise 31: Making Decisions EXTRA CREDIT EDITION
def prompt
print ">"
end
bear_hp = 100
def weapon(stuff)
if stuff == 'sword'
return sword = 50
elsif stuff == 'hammer'
return hammer = 75
elsif stuff == 'spoon'
return spoon = 9001
else
something_else = 'stuff'
end
end
puts "You enter... | true |
c37a0c3d5ca160424aeff98037c769997762fefa | Ruby | myles-mv/rb-modules | /lib/table.rb | UTF-8 | 3,173 | 3.296875 | 3 | [
"MIT"
] | permissive | class Table
attr_reader :headers, :data, :meta_data
def initialize(headers, data)
@headers = sanitize(headers)
@data = data.map(&method(:sanitize))
raise ArgumentError unless TableValidator.valid?(self)
end
private
def sanitize(data)
data.map do |d|
d.to_s.capitalize
end
end
en... | true |
6dac4afd4e87b01686137e6461b07d3e9e3b4262 | Ruby | lube8uy/petirrojo-in-rails | /lib/twitter/twitter_rest_client.rb | UTF-8 | 2,123 | 3.078125 | 3 | [] | no_license | require 'net/http'
require 'json'
class TwitterRestClient
def get_trends
get('http://api.twitter.com/1/trends/daily.json')
end
def get_twits_for_trend(trend)
check_string_argument(trend)
get('http://search.twitter.com/search.json', {'q' => trend.to_s.strip})
end
def get_twit_by_id(id)
check_id_argume... | true |
fd893eedd8a61d6c52cb993845f004a7b6f1432e | Ruby | KenDaryn/cd | /+Массив от 5 до 100.rb | UTF-8 | 73 | 3.15625 | 3 | [] | no_license | array = (5..100).to_a
a = array.find_all{ |elem| elem % 5 == 0 }
puts a | true |
79315f82510aae946da961235b258af0237a2507 | Ruby | itsolutionscorp/AutoStyle-Clustering | /assignments/ruby/combine_anagrams/feature/whelper_source/15620.rb | UTF-8 | 243 | 3.21875 | 3 | [] | no_license | def combine_anagrams(words)
hash = Hash.new("")
words.each do |element|
hash[element.downcase.chars.sort.join] += (" " + element)
end
arr = []
hash.each do |k, v|
temp = v.split(" ")
(arr << temp)
end
return arr
end
| true |
9a1667d367b2dc96783a5c22ee9a09b9731a137d | Ruby | paulshaoyuqiao/ics_bc_s18 | /week1/ch02/age_in_seconds.rb | UTF-8 | 203 | 2.90625 | 3 | [] | no_license | basic_year_days = (2018-1868)*365
leap_year_days = 37
days_since_last = 8 + 61*4 + 21
total_days = basic_year_days + leap_year_days + days_since_last
puts "I think the answer is #{total_days*24*60*60}." | true |
de6456cce166a760bb7233a52a407667358f6bc7 | Ruby | seanhawkridge/takeaway-challenge | /spec/restaurant_spec.rb | UTF-8 | 2,251 | 3.0625 | 3 | [] | no_license | require 'restaurant'
describe Restaurant do
let(:menu_klass) {double :menu_klass}
let(:menu) {double :menu}
let(:text_klass) {double :text_klass}
subject(:restaurant) { described_class.new(menu_klass, text_klass) }
before do
allow(menu_klass).to receive(:new)
allow(menu_klass).to receive(:list).a... | true |
5a309474206652c7fff32395b53feb0a12e7cbf2 | Ruby | urimikhli/urlshorten | /spec/models/shorten_spec.rb | UTF-8 | 1,793 | 2.625 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
RSpec.describe Shorten, type: :model do
describe '#validations' do
#Factory needs to be tested with the arbitrary non null values
let(:shorten) { build(:shorten) }
#Use static slug values to test validations
let(:shorten_static) { create(:shorten, slug: 'slug') }
let(:shor... | true |
bc663da0d02c838396a25267b5c3990175740e4e | Ruby | focuslight/focuslight | /lib/focuslight/logger.rb | UTF-8 | 2,077 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'logger'
require "focuslight/config"
module Focuslight
module Logger
def self.included(klass)
# To define logger *class* method
klass.extend(self)
end
# for test
def logger=(logger)
Focuslight.logger = logger
end
def logger
Focuslight.logger
end
end
... | true |
63652b14300b770f5ff6419449e209c19b4a6dc7 | Ruby | mwwong/home_work | /w2d3/skeleton/spec/dessert_spec.rb | UTF-8 | 1,986 | 3.546875 | 4 | [] | no_license | require 'rspec'
require 'dessert'
=begin
Instructions: implement all of the pending specs (the `it` statements without blocks)! Be sure to look over the solutions when you're done.
=end
describe Dessert do
subject(:sugar) { Dessert.new("sugar", 30, chef) }
let(:chef) { double("Ramsay") }
describe "#initiali... | true |
30d1771357f9bb28e708638cd6f849041bb41e0e | Ruby | robert-laws/learning-apr-2019-ruby-classes-and-modules | /classes/dice_set.rb | UTF-8 | 383 | 3.734375 | 4 | [] | no_license | # DiceSet class
class DiceSet
# attr_reader :dice_array # optional - display will do the same thing
def initialize
@dice_array = [Dice.new, Dice.new]
end
def display
# "[#{dice_array[0].value}] - [#{dice_array[1].value}]"
@dice_array.map { |d| "[ #{d.value} ]"}.join(" - ")
end
... | true |
d6acf633cded05c2b663efbf654473c782353b01 | Ruby | Dvvuuh/Exo0704 | /exo_11.rb | UTF-8 | 124 | 3.328125 | 3 | [] | no_license | puts "hey toi ! Choisi un nombre"
print "> "
numbers=gets.chomp.to_i
numbers.times do
puts "Salut, ça farte ?"
end | true |
36ef59f3776f6aaaf2d631996a146ec52801464b | Ruby | saito/smcweb | /lib/smcweb/base_path.rb | UTF-8 | 840 | 2.59375 | 3 | [] | no_license | module Smcweb
class BasePath
# parse path like /news/{date14}_en.html.smc
#
# return {
# :root => "/news",
# :type => "date14"
# :prefix => "",
# :suffix => "_en.html.smc"
# }
def parse_string_path_config(str)
result = {}
unless str =~ /\{([-\w]+?)\}/
... | true |
a688d96c99c4a3a2f8114f3d3976cc6c4a2b0f57 | Ruby | mattdizon/Corus | /medical.rb | UTF-8 | 644 | 2.828125 | 3 | [] | no_license | require 'net/http'
require 'json'
require 'date'
def getRecords(ageStart, ageEnd, bpdiff)
current_year = DateTime.strptime("1318996912",'%s').year()
ids = []
uri = ("https://jsonmock.hackerrank.com/api/medical_records")
resp = Net::HTTP.get_response(URI.parse(uri))
initial_data = resp.body
pars... | true |
66ac64133ce51d4340cb88bd80861bda51c46a93 | Ruby | zzuu666/leetcode-ruby | /nine/40.组合总和-ii.rb | UTF-8 | 1,453 | 3.40625 | 3 | [] | no_license | #
# @lc app=leetcode.cn id=40 lang=ruby
#
# [40] 组合总和 II
#
# https://leetcode-cn.com/problems/combination-sum-ii/description/
#
# algorithms
# Medium (63.95%)
# Likes: 551
# Dislikes: 0
# Total Accepted: 145.8K
# Total Submissions: 228.5K
# Testcase Example: '[10,1,2,7,6,1,5]\n8'
#
# 给定一个数组 candidates 和一个目标数 tar... | true |
2e27ccf8941ccda0b401ff8571d037e7e3535122 | Ruby | lcmidori/coding | /FizzBuzz/fizzbuzz.rb | UTF-8 | 193 | 3.65625 | 4 | [] | no_license | a = (1..100).to_a
a.each do |e|
if e % 3 == 0 && e % 5 == 0
print "FizzBuzz "
elsif e % 3 == 0
print "Fizz "
elsif e % 5 == 0
print "Buzz "
else
print "#{e} "
end
end
| true |
09edd9d2ed25dce892f68baa0b4ba41de04b44cc | Ruby | mattantonelli/pokodox | /app.rb | UTF-8 | 378 | 2.609375 | 3 | [] | no_license | require 'bundler'
Bundler.require
POKEZ = File.readlines('pokez.txt').map(&:chop)
get '/' do
{ status: :ok, count: POKEZ.count }.to_json
end
get '/pokez/:id' do
id = params[:id].to_i
name = POKEZ[id - 1]
artwork = "http://img.pokemondb.net/artwork/#{name.sub('. ', '-').downcase}.jpg"
{ id: id, name... | true |
d89a01e13c5050d0f977fb45cee6d594706936be | Ruby | oliviagunton/rspec-fizzbuzz-001-prework-web | /fizzbuzz.rb | UTF-8 | 170 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def fizzbuzz(n)
ret = ""
if n % 3 == 0
ret.concat("Fizz")
end
if n % 5 == 0
ret.concat("Buzz")
end
if(ret == "")
nil
else
ret
end
end
| true |
c1ffaea53fe8c90a32a77f8feaebaf74910cfea1 | Ruby | kenchan/competitive_programming | /atcoder/abc154/c.rb | UTF-8 | 84 | 2.71875 | 3 | [] | no_license | n = gets.to_i
a = gets.split.map(&:to_i)
puts a.size == a.uniq.size ? 'YES' : 'NO'
| true |
6bd1948d69313b026196c14eea440d2291d3d39a | Ruby | kubarazny/AlfaRomeo | /app/models/user.rb | UTF-8 | 640 | 2.640625 | 3 | [] | no_license | class User < ActiveRecord::Base
has_secure_password
EMAIL_REGEX = /\A[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}\Z/i
validates :name,
presence: true
validates :surname,
presence: true
validates :user,
length: { within: 4..25, message: "nazwa użytkownika musi ... | true |
b7a12a83f7224eef0d115323ffb70c49d60b2c9a | Ruby | ZishJawaid/Bank-Account-App | /lib/account.rb | UTF-8 | 986 | 3.359375 | 3 | [] | no_license | require_relative 'statement'
require_relative 'transactions'
class Account
attr_reader :balance, :transactions, :transaction_log, :new_statement
def initialize(balance = 0)
@balance = balance
@transactions = Transactions.new
@transaction_log = transactions.transaction_log
@new_statement = Statem... | true |
c1870114db8b236f4e0b1defcef495ef588b482f | Ruby | rvm/tf | /lib/plugins/tf/env_arr_test.rb | UTF-8 | 2,385 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | class TF::EnvArrTest
MATCHER = {
:all => /^env\[([a-zA-Z_][a-zA-Z0-9_]*)\]\[\]([!]?=)[~]?\/(.*)\/$/,
:one => /^env\[([a-zA-Z_][a-zA-Z0-9_]*)\]\[(.+)\]([!]?=)[~]?\/(.*)\/$/,
:size => /^env\[([a-zA-Z_][a-zA-Z0-9_]*)\]\[\]([!]?=)([[:digit:]]+)$/,
}
def matches? test
TF::EnvArrTest::MATCHER.find{|k... | true |
fdf991ca391fa4cfdc2acb03d1b1f7d1349eadb1 | Ruby | haileys/jellyfish | /lib/jellyfish/parser.rb | UTF-8 | 3,992 | 2.671875 | 3 | [] | no_license | require "ripper"
module Jellyfish
class Parser
def initialize(source)
source = Ripper.sexp source unless source.is_a? Array
raise Error, "syntax error" unless source and source[0] == :program
@sexp = source[1][0]
end
def parse
transform_node @sexp
end
def transfo... | true |
1ae36d4886efed76e76a72933c393be8dfc17cb2 | Ruby | sfahado/CodilityInRuby | /libs/maximumsliceproblem/max_profit.rb | UTF-8 | 528 | 3.15625 | 3 | [
"MIT"
] | permissive | # This is the solution for Maximum Slice Problem > Max Profit
#
# This is marked as PAINLESS difficulty
class MaxProfit
def solution(a)
global_max_sum = 0
local_max_sum = 0
for i in 1..a.size - 1
d = a[i] - a[i - 1]
local_max_sum = [d, local_max_sum + d].max
global_max_sum = [local_max_... | true |
a546da2ff6b54a47f06e628e87192c76f77448fe | Ruby | tanmdoan/Flashcards | /lib/flashcard_runner.rb | UTF-8 | 1,002 | 3.796875 | 4 | [] | no_license | require './lib/round'
require './lib/deck'
# require './lib/guess'
# require './lib/card'
class FlashCardRunner
def start
puts "Welcome! You're playing with 4 cards."
puts "-------------------------------------------------"
deck = Deck.new
round = Round.new(deck)
until round.card_number do
puts "T... | true |
e44b36656fc00774451eebc5be938b26abcda2bd | Ruby | cshtdd/ruby-pgp | /spec/lib/quirks_spec.rb | UTF-8 | 2,149 | 3 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'tempfile'
describe 'RSpec multiple yields quirks' do
##
## I wrote this test to capture my lack of understanding on how to mock a method that yields multiple times
##
#it 'this should work' do
# stub1 = double
# allow(stub1).to receive(:path).and_return('path1')
#
# st... | true |
4d279d163226b6eb95b562164298dde028c7d4db | Ruby | FergusLemon/oyster_card | /lib/oystercard.rb | UTF-8 | 865 | 3.359375 | 3 | [] | no_license | class Oystercard
LIMIT = 90
DEFAULT_BALANCE = 0
MINIMUM_BALANCE = 1
attr_reader :balance
def initialize(balance = DEFAULT_BALANCE, journey_klass = Journey)
@balance = balance
@journey_klass = journey_klass.new
end
def topup(value)
fail "You have exceeded the balance limit of £#{LIMIT}" if card_full... | true |
3a247b9e9280b25b54c288c769520111ef117907 | Ruby | madmax/ruby_php_session | /lib/php_session/decoder.rb | UTF-8 | 6,999 | 2.75 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
class PHPSession
class Decoder
attr_accessor :buffer, :state, :stack, :array
attr_reader :encoding, :encoding_option
def self.decode(string, encoding = nil, encoding_option = {})
if string.nil?
string = ""
end
string.chomp!
self.new(string, encoding... | true |
5fbc2f84696a04d74701ddee9adda64d4eaabaa9 | Ruby | tianyuduan/algorithms | /algopractice5.rb | UTF-8 | 2,210 | 4.3125 | 4 | [] | no_license | Inner HTML VS. Append Child
What is the best way to create a DOM element? Set innherHTML or use createElement?
Answer
When you set the innerHTML property, the browser removes all the current children of the elements. Parses the string and assigns the parsed string to the element as children.
For example, if you want t... | true |
99712f2ae93ea4405dff64b5945b688c422c9142 | Ruby | aimeerivers/ruby_design_patterns | /creational_patterns/abstract_factory/test.rb | UTF-8 | 1,758 | 2.765625 | 3 | [] | no_license | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
require 'test/unit'
class TestAbstractFactory < Test::Unit::TestCase
def test_normal_maze_factory_creates_normal_rooms
maze = MazeGame.create_maze(MazeFactory.new)
assert_equal... | true |
cf3be6640426f535bd301c93bbc2fa6b72320a91 | Ruby | guineveresaenger/cs-fun-practice | /problem2_2.rb | UTF-8 | 242 | 3.453125 | 3 | [] | no_license | def switchPairs(array)
i = 0
while i < (array.length - 2)
temp = array[i]
array[i] = array[i+1]
array[i+1] = temp
i += 2
end
return array
end
a = ["to", "be", "or", "not", "to", "be", "hamlet"]
print switchPairs(a)
| true |
731ac9bcf68e695624054405bf467794859da572 | Ruby | libsyz/snippet-search-app | /db/seeds.rb | UTF-8 | 563 | 2.78125 | 3 | [] | no_license |
require 'roo'
require_relative 'snippet_factory'
# Instantiated in different variables to avoid weird behavior
seed_file1 = Roo::Spreadsheet.open('./Book1.xlsx')
seed_file2 = Roo::Spreadsheet.open('./Book1.xlsx')
strengths = seed_file1.sheet('strengths')
weaknesses = seed_file2.sheet('aods')
snippet_factory = Snipp... | true |
b1d33410f5e5a7e18dd0598a340ce0c497809fe0 | Ruby | lotherk/rarma | /lib/rarma/cli/subcommand/compile.rb | UTF-8 | 3,370 | 2.640625 | 3 | [
"MIT"
] | permissive | <<<<<<< HEAD
require 'rarma/sqf/compiler'
require "fileutils"
class PackagesList
attr_accessor :packages
def initialize
@packages=[]
end
def get_binding
binding
end
end
class Rarma::CLI::Subcommand::Compile
attr_reader :description
def initialize
@description = "Compile ruby to sqf"
end
de... | true |
7603a53b41bf1cae14719895495c2b2a600e4321 | Ruby | derkrisz/week_3_weekend_homework | /models/ticket.rb | UTF-8 | 1,037 | 3.03125 | 3 | [] | no_license | require('pg')
require_relative('../db/sql_runner')
class Ticket
def initialize(options)
@id = options['id'].to_i if options['id']
@customer_id = options['customer_id'].to_i
@film_id = options['film_id'].to_i
end
def save
sql = "INSERT INTO tickets (customer_id, film_id) VALUES ($1, $2) RETURNING *"
values ... | true |
00c5ca3dc19f3fd61822a66661eed6f27d41e930 | Ruby | klmov/mtn18 | /homeworks/kanstantsin_klimov_l1.rb | UTF-8 | 2,123 | 3.078125 | 3 | [] | no_license | #!/usr/bin/env ruby
=begin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* TASK 1
*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=end
def task_2(log)
result = []
unless l... | true |
8016fdd8b643675245efd1cb4461d11753f132c7 | Ruby | kapoq/nyan | /spec/lib/shape_spec.rb | UTF-8 | 1,153 | 3.046875 | 3 | [] | no_license | require 'spec_helper'
class SimpleShape
include ::Nyan::Shape
def initialize
@top, @bottom, @left, @right = [0, 0, 0, 0]
end
end
describe Nyan::Shape do
let(:shape) { SimpleShape.new }
describe "#outside?" do
let(:other_shape) { SimpleShape.new }
it "is outside when its right edge is be... | true |
25a7648f5be857ab382b3896bba0b2bdb2a2ff6c | Ruby | kaikousa/hello-api | /ruby/app.rb | UTF-8 | 668 | 2.6875 | 3 | [] | no_license | # frozen_string_literal: true
require 'sinatra'
# Main application
class App < Sinatra::Application
def json_body
request.body.rewind
body = request.body.read
return JSON.parse(body) unless body.empty?
{}
end
get '/' do
'Hello World!'
end
get '/status' do
'ok'
end
get '/echo... | true |
f7809094b926ee37afe3a3dddc36bdf3bf808329 | Ruby | jcquarto/everything-is-a-object-or-method | /method_test5.rb | UTF-8 | 363 | 3.734375 | 4 | [] | no_license | # what about method calls without a receiver?
def santa_says( msg )
"HoHoHo! Santa says #{msg}"
end
puts santa_says("No presents for you!")
puts "----------------------"
puts self.send(:santa_says, "No presents for you!")
# why does this work? Because everything is an object! So "self" always
# refers to *somethi... | true |
b85c8d3be000c5b1ff27904e4785323a8d4ac650 | Ruby | chandraphang/PokemonRainbow | /spec/models/battle_engine_spec.rb | UTF-8 | 10,772 | 2.71875 | 3 | [] | no_license | require 'rails_helper'
describe BattleEngine do
before(:each) do
pokedex = Pokedex.new
pokedex.name = 'pokemon'
pokedex.base_health_point = 10
pokedex.base_attack = 10
pokedex.base_defence = 10
pokedex.base_speed = 10
pokedex.element_type = 'normal'
pokedex.save
@pokemon_attacker... | true |
9ccfd899be2e794311645908481e446bdd85b839 | Ruby | arirusso/topaz | /examples/midi_output.rb | UTF-8 | 443 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
$:.unshift(File.join("..", "lib"))
require "topaz"
# Send MIDI clock messages to a MIDI output
# A mock sequencer
class Sequencer
def step
@i ||= 0
p "step #{@i+=1}"
end
end
# Select a MIDI output
@output = UniMIDI::Output.gets
sequencer = Sequencer.new
# This sets quarter note =... | true |
be6775a85369cb2032859920ccfbab7577bd8fb9 | Ruby | flemdizzle/pomodoro | /db/seeds.rb | UTF-8 | 769 | 2.53125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.