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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
345764c73283190d04e12b34281aac22a0efca5c | Ruby | zaccari/torquebox | /integration-tests/apps/rails3/injection/app/models/enumerable_thing.rb | UTF-8 | 280 | 2.75 | 3 | [] | no_license | class EnumerableThing
include Enumerable
def initialize
@hash = { :a => :b }
queue = TorqueBox.fetch('/queues/injection_enumerable')
inject('this should not barf') { |_, __| queue.publish('it worked') }
end
def each(&block)
@hash.each(&block)
end
end
| true |
bda0f27355632d4ee54a074611090c297fc888cd | Ruby | LeoDaza7/tx-hg-dictionary | /app/models/service_object/oxford_api.rb | UTF-8 | 1,995 | 2.515625 | 3 | [] | no_license | class ServiceObject::OxfordApi
def self.get_definition(word)
result = {
"status_code" => 0,
"definition" => "N/A",
"message" => ""
}
# important, headers required to make request to the oxford API
headers = {
"app_id" => ENV["APP_ID"],
"app_key" => ENV["APP_KEY"]
}
... | true |
2ebe3df17522b9f88d4ba48e3ce11b792910a5c5 | Ruby | poymanov/railswinter2017 | /np1/lesson07/task-07-06.rb | UTF-8 | 803 | 3.265625 | 3 | [] | no_license | # encoding: utf-8
# Список покупок
shoplist = ["масло", "молоко", "хлопья", "картошка", "курица", "помидоры"]
puts "Нужно купить"
puts shoplist.to_s
while shoplist.size > 0 do
# Спрашиваем что купили, пока массив не станет пустым
puts "Что купили?"
# Получаем ответ пользователя
product = gets.encode("UTF-8"... | true |
79bb1a09bf19b86951895acaf92d51980c3b4dea | Ruby | ridiculous/duck_puncher | /lib/duck_puncher/decoration.rb | UTF-8 | 970 | 2.703125 | 3 | [
"MIT"
] | permissive | module DuckPuncher
# @note When updating this file please update comment regarding this module in duck_puncher.rb
module Decoration
def decorators
@decorators ||= ancestral_hash
end
def build_decorator_class(*ducks)
targets = ducks.sort.map(&:target)
decorator_class = DelegateClass(ta... | true |
1a1aa7fc992fd5815892b329705f6111bb55fb77 | Ruby | Nosfheratu/ruby-practices | /methods.rb | UTF-8 | 910 | 3.5625 | 4 | [] | no_license | # encoding: utf-8
# Classes
class Post
attr_reader :author, :title, :body, :comments
def initialize options
@author = options[:author]
@title = options[:title]
@body = options[:body]
@comments = options[:comments] || []
end
def insert_comment *comments
comments.each { |c| @comments << c }
end
end
c... | true |
dc979ce5ad9bb3cbf3f5a4190a723cac53547a3e | Ruby | bryalara/CSCE_431_SoftwareEngineering | /Lab_1/Calculator_practice.rb | UTF-8 | 644 | 3.875 | 4 | [] | no_license |
puts "First number? "
first = gets.chomp.to_i
puts "Second number? "
second = gets.chomp.to_i
puts "you entered #{first} and #{second}"
puts "what do you want to do? add, subtract, divide, multiply, circlearea"
choice = gets.chomp
case choice
when "add"
# add up the first and second
when "circle... | true |
4d9c185c677afd200877741706e0d2d6010c77ac | Ruby | rthbound/advent-of-code-2017 | /18/solution_part_two.rb | UTF-8 | 2,018 | 3.359375 | 3 | [] | no_license | require 'pry'
register = "a".upto("z").to_a.zip([0]*26).to_h
@registers = {
0 => { register: register.dup, queue: [], counter: 0, sent_log: []},
1 => { register: register.dup, queue: [], counter: 0, sent_log: []}
}
@registers[0][:register]["p"] = 0
@registers[1][:register]["p"] = 1
def relay_instructions(set)
... | true |
e01be826ca546f6e7ff89f97207d7f9492956091 | Ruby | skaidra-bake/ruby_challenges | /bank_card_number_encryption/mask.rb | UTF-8 | 141 | 2.796875 | 3 | [] | no_license | # to encrypt all except the last 4 characters of the bank card number
def mask(str)
str[0..-5] = '#' * (str.length - 4)
str
end | true |
4524a2477e4f97ede567b44b79f0c2789673710a | Ruby | kasharaylo/RubyCore-Selenium | /Screencast/ep17/ep17.rb | UTF-8 | 341 | 3.234375 | 3 | [] | no_license | class Cart2
# Getter
attr_reader :books
def initialize
@books = []
end
def add_items(item)
@books.push item
end
def remove_items
@books.pop
end
def validate
@books.each { |i| puts "Items has no price" if i.price.nil? }
end
def delete_invalid_items
@books.delete_if { |i| i.p... | true |
adaec010629f890144310fae6adc442ed91211b7 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/nucleotide-count/62265c80d3974ca284043dd06cbf3c5a.rb | UTF-8 | 612 | 3.84375 | 4 | [] | no_license | class DNA
NUCLEOTIDES = 'ATCG'.chars
def initialize(sequence)
raise ArgumentError unless valid_sequence? sequence
@sequence = sequence
end
def count(nucleotide)
raise ArgumentError unless valid_nucleotide? nucleotide
@sequence.count(nucleotide)
end
def nucleotide_counts
Hash[NUCLEOTID... | true |
1167d398c8130dbb8cd2be528d2bdfeb0569bd6d | Ruby | ladeeluc/square_array-ruby-apply-000 | /square_array.rb | UTF-8 | 140 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def square_array(numbers)
new_array =[]
#binding.pry
numbers.each {|x|
new_array << x * x
}
new_array
end
| true |
34aedc8f1f922f0b61a955bb0f58e47b102a7dd0 | Ruby | Neilda/ruby_challenges | /always_three.rb | UTF-8 | 161 | 3.5625 | 4 | [] | no_license | def always_three (number)
(((number+5)*2-4)/2-number)
end
puts "Give me a number"
first_number = gets.to_i
puts 'Always ' + always_three(first_number).to_s | true |
1c2681d62b58fc28d04a507b3d20414f8c5167ad | Ruby | yamiacat/week4-homework | /pizza_shop_sinatra/db/seeds.rb | UTF-8 | 475 | 2.640625 | 3 | [] | no_license | require_relative('../models/pizza')
Pizza.delete_all()
pizza1 = Pizza.new({
"first_name" => "Walter",
"last_name" => "White",
"topping" => "Pepperoni",
"quantity" => 1
})
pizza2 = Pizza.new({
"first_name" => "Jesse",
"last_name" => "Pinkman",
"topping" => "Italian Sausage",
"quantity" => 12
})
piz... | true |
e93e5787935680cdc94dac604303c470b225f4f7 | Ruby | gior/sortable_by | /spec/sortable_by/sortable_by_spec.rb | UTF-8 | 1,206 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe SortableBy do
before(:all) do
class SortableClass < ActiveRecord::Base
#extend SortableBy
sortable_by :title
sortable_by :code, 'desc'
end
end
before(:each) do
@sortable1 = FactoryGirl.create(:sortable_class, title: 'srt1', code: '1st')
@sortabl... | true |
425efa5c471a866445d76b5b29ec8cd4bfcbd71c | Ruby | bc-nogueira/educacao_gpms | /app/validators/discount_validator.rb | UTF-8 | 1,046 | 2.65625 | 3 | [] | no_license | class DiscountValidator < ActiveModel::Validator
def validate(record)
validate_date_exists(record)
validate_dates_order(record)
end
def validate_date_exists(record)
null_dates_error = validate_null_date(record)
same_date_error = validate_same_date(record)
return unless null_dates_error || sam... | true |
36c56b42348fa7ff4dc059f65534977c12e57e8b | Ruby | pprince/scribbles-ruby | /001-isbn/isbn.rb | UTF-8 | 827 | 3.140625 | 3 | [] | no_license | module Isbn
def Isbn.check_isbn10(input)
match = input.delete(' -').match(/^(\d{9})(\d|X)$/)
return false unless match
digits = match[1].chars.map{|c| c.to_i}
checkdigit = case match[2]
when 'X'
10
else
match[2].to_i
... | true |
662f65beae927bcd22eceb33a09856e5fa9df5bc | Ruby | gitter-badger/pro | /servers/ruby/string.rb | UTF-8 | 144 | 2.671875 | 3 | [
"LicenseRef-scancode-wtfnmfpl-1.0"
] | permissive | class String
def camelize
split('/').map{ |word| word.capitalize}.join('::')
end
def constantize
Object.const_get self
end
end
| true |
14775017604b082e3dcb92dcb9363158324c0a72 | Ruby | rlister/stax | /lib/stax/base.rb | UTF-8 | 4,260 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'thor'
require 'stax/aws/sts'
require 'aws-sdk-ssm'
## clean exit on ctrl-c for all methods
trap('SIGINT', 'EXIT')
module Stax
class Base < Thor
no_commands do
def app_name
@_app_name ||= options[:app].empty? ? nil : cfn_safe(options[:app])
end
def branch_name
@_branc... | true |
681001380520410ec7b4628c0dbece57270dc14f | Ruby | ghas-results/sonic-midi | /lib/sonic_play.rb | UTF-8 | 1,253 | 3.03125 | 3 | [
"Apache-2.0"
] | permissive | # Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, ... | true |
5f893052cdb1f86500d1162ef22d3d95cc49db62 | Ruby | cleancoindev/fulcrum-photo-importer | /import-photos.rb | UTF-8 | 1,856 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'bundler/setup'
require 'thor'
require 'json'
require 'fulcrum'
require 'csv'
require 'colorize'
Bundler.setup(:default)
VALID_UUID = /\A([0-9a-fA-F]{32}|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\z/
class Import < Thor
desc "import", "import photos"
... | true |
15bb2ffc53594f87ab1b89211ffd44c3835a505a | Ruby | arthurljones/junkrig-calc | /export/crane.rb | UTF-8 | 1,153 | 2.609375 | 3 | [] | no_license | require_relative "../boilerplate"
require "crane"
require "export_helper"
crane = Crane.new({})
require 'ruby-prof'
RubyProf.start
objects = (0..90).step(1).map do |angle|
crane.calculate(Unit.new(angle, "deg"))
end
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
#printer.print(STDOUT)
#puts
#... | true |
de7636960d37c5853817090f95ae87cc2dd8e5fc | Ruby | latinman/wyncode_projects | /quad.rb | UTF-8 | 366 | 3.46875 | 3 | [] | no_license | class Quadrilateral
end
class Rectangle < Quadrilateral
end
class Square < Rectangle
end
class Trapezoid < Quadrilateral
end
class Rhombus < Trapezoid
end
def test
squa = Square.new
puts squa.is_a? Rectangle
puts squa.is_a? Quadrilateral
rect = Rectangle.new
puts rect.is_a? Quadrilateral ... | true |
f0f9b03e3e0f8714417a3c0a3d34a08210f83ee5 | Ruby | blambeau/dbagile | /lib/dbagile/environment/interactions.rb | UTF-8 | 6,702 | 3.578125 | 4 | [
"MIT"
] | permissive | module DbAgile
class Environment
#
# Environment's interactions contract.
#
module Interactions
# The buffer to use for displaying messages
attr_reader :message_buffer
# The buffer to use for asking questions
attr_reader :asking_buffer
################... | true |
6333fa1b610edeef299c103579b7c724c1509be2 | Ruby | seemajune/Flatiron-Prework | /englishNumbers.rb | UTF-8 | 2,032 | 3.984375 | 4 | [] | no_license | def englishNumber number
# We only want numbers from 0-100.
if number < 0
return 'Please enter a number zero or greater.'
end
if number > 10_000
return 'Please enter a number 10,000 or lesser.'
end
numString = ''
onesPlace = ["one", "two", "three", "four", "five", "six", "seven", "eight", "... | true |
47750734086eeb19b83591152683216257cacb33 | Ruby | camillavk/FAAST_2 | /lib/passenger_holder.rb | UTF-8 | 505 | 3.484375 | 3 | [] | no_license | module PassengerHolder
DEFAULT_CAPACITY = 40
attr_reader :capacity
def initialize(options = {})
@capacity = options.fetch(:capacity, DEFAULT_CAPACITY)
@passengers ||= []
end
def accept(passenger)
@passengers << passenger
end
def release(passenger = nil)
@passe... | true |
ba196bd1afd7c3df2c17b488203bca4976c48121 | Ruby | thomasstephane/flashquizz | /app/models/card.rb | UTF-8 | 169 | 2.578125 | 3 | [] | no_license | class Card < ActiveRecord::Base
belongs_to :deck
validates :question, :answer, :presence => true
def check(user_answer)
self.answer == user_answer
end
end
| true |
4ffe1417def03e471ae6a9dd1578913c05ccface | Ruby | wcln/course_html_formatter | /fclipboard.rb | UTF-8 | 2,172 | 2.90625 | 3 | [] | no_license | require 'clipboard' # https://github.com/janlelis/clipboard
require 'uri'
require 'time'
require 'open-uri'
require 'launchy'
###### SETTINGS #######
CURRENT_COURSE = ''
CURRENT_SECTION = ''
GENERATE_LOG = true
#######################
CONTENT_SERVER_DOMAIN_NAME = ''
contents = Clipboard.paste.encode('UTF-8') # fetch... | true |
8bfa7313a62f587f2538508639833f4576e6a912 | Ruby | dublado/whos_dated_who | /lib/whos_dated_who/parser.rb | UTF-8 | 2,417 | 2.671875 | 3 | [
"MIT"
] | permissive | module WhosDatedWho
class Parser
attr_reader :doc
def parse(body)
@doc = Nokogiri::HTML(body)
extract_bio
extract_current_relationship
# TODO: extract_past_relationships
@result
end
def result
@result ||= Hashie::Mash.new(biography: @biography, status: :unknown)
... | true |
d4a863e9a37a68ea6b4a4e710e68563d0fdd5ed5 | Ruby | edavis10/shopify_theme | /lib/shopify_theme/file_filters.rb | UTF-8 | 457 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'shopify_theme/filters/blacklist'
require 'shopify_theme/filters/whitelist'
require 'shopify_theme/filters/command_input'
module ShopifyTheme
class FileFilters
def initialize(*filters)
raise ArgumentError, "Must have at least one filter to apply" unless filters.length > 0
@filters = filters
... | true |
98872b243c7ec35579ebd3db2b1efa7424bf6497 | Ruby | feiqin/feiliga1 | /caculator.rb | UTF-8 | 3,069 | 3.078125 | 3 | [] | no_license | class Caculator
require 'rubygems'
require 'json'
require 'net/http'
load "team.rb"
attr_accessor :teams, :matches
def initialize(teamsList)
@matches = getMatches()
@teams = teamsList
end
def getMatches()
url = "http://botliga.de/api/matches/2011"
resp = Net::HTTP.get_response(U... | true |
5bd960f1b2eeda0766087083f2426cee8b46b581 | Ruby | 4thAce/careercup | /spec/commonestword_spec.rb | UTF-8 | 429 | 2.765625 | 3 | [] | no_license | require_relative "../commonestword"
RSpec.describe "CommonestWord::mostcommon" do
it "can read pg11.txt and returns the" do
c = CommonestWord.new
result = c.mostcommon('pg11.txt')
expect(result).to eq('the')
end
end
RSpec.describe "CommonestWord::concordance" do
it "returns a Hash" do
c = Commo... | true |
b43c2d6f2b5efa06c5c4398e0057b4e627d191e4 | Ruby | picandocodigo/gamesdb | /lib/thegamesdb/utils.rb | UTF-8 | 1,716 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Gamesdb
# Several reusable functions
module Utils
class << self
def process_logo(data, id)
logo = data['images'][id.to_s].select { |a| a['type'] == 'clearlogo' }
logo.empty? ? '' : logo.first['filename']
end
def process_fanart(data, id)
... | true |
0d6c08f47ecc1cc5d40a40824ff6accddb9a1358 | Ruby | othiym23/ingestion-tools | /bin/cache_pending_to_db | UTF-8 | 8,028 | 2.640625 | 3 | [] | no_license | #!/usr/bin/env ruby
script_path = __FILE__
script_path = File.readlink(script_path) if File.symlink?(script_path)
$KCODE = 'u'
$: << File.join(File.dirname(script_path), '../lib')
require 'find'
require 'dao/album_dao'
require 'adaptor/euterpe_dashboard_factory'
ARCHIVE_ROOT = '/data'
PENDING_BASE = ARCHIVE_ROOT + ... | true |
457610b5870395b96420b3f5dca16f38cd17d316 | Ruby | 47primes/cc_processor | /lib/cc_processor/credit_card.rb | UTF-8 | 1,607 | 2.953125 | 3 | [] | no_license | module CCProcessor
class CreditCard < ActiveRecord::Base
self.table_name = :credit_cards
before_validation :strip_name_and_number
validates :name, presence: true, uniqueness: true
validates :number, presence: true, length: { maximum: 19 }
validates :limit, presence: true, numericality: {... | true |
a97baae2537e5fce8799282def0580339b51fe5d | Ruby | ljwoodward/project_burger_tracker | /burger_tracker/models/burgerdeal.rb | UTF-8 | 1,319 | 3.140625 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
require_relative('deal.rb')
require_relative('burger.rb')
class BurgerDeal
attr_reader(:id, :deal_id, :burger_id)
def initialize(options)
@id = options['id'].to_i if options['id']
@deal_id = options['deal_id'].to_i
@burger_id = options['burger_id'].to_i
end
... | true |
04161d5eeeab33aefc46d0b03c60b676183f403b | Ruby | RomanADavis/challenges | /euler/ruby/solved/problem_set(1-25)/problem10/solutions/solution.rb | UTF-8 | 694 | 4.03125 | 4 | [] | no_license | # Takes about a minute on my computer. Wondering how I can make this faster.
def primes_under(n)
primes = [2]
candidate = 3
while candidate < n
factors = primes[1...primes.index {|prime| prime > candidate**0.5 }]
primes << candidate unless factors.any? {|factor| candidate % factor == 0}
candidate += ... | true |
6d552cfd28a2d251596b4284c6ab8931e46bbb86 | Ruby | rikkimalh/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 1,119 | 4.28125 | 4 | [] | no_license | # Algorithm:
#encrypt method:
#Agent enters code. Code is received and converted to move encryption forward one letter.
#Return value will be sent back to user with correct plus one format
#Spaces will not count toward letters and will be a space
#decrypt method:
#reverses the encrypt process
#user enters encrypted ... | true |
04584a413c18c2ce7644eb785fa0bca03c083826 | Ruby | BickelmannB/rails-mister-cocktail | /db/seeds.rb | UTF-8 | 320 | 2.609375 | 3 | [] | no_license | require 'open-uri'
require 'json'
# url = 'https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list'
# document = JSON.parse(URI.parse(url).open.read)
# document['drinks'].each do |ingredient|
# Ingredient.create!(name: ingredient['strIngredient1'])
# end
Cocktail.new(name: 'lemon')
Cocktail.new(name: 'orange')
| true |
86a87ae9c95153e0002c6650326cb413b8563d67 | Ruby | Vaent/calculator | /spec/calculator_spec.rb | UTF-8 | 379 | 2.921875 | 3 | [] | no_license | require 'calculator'
describe(Calculator) do
describe('#multiply') do
it { expect(subject.multiply(2,3)).to eq('the answer is 6') }
it { expect(subject.multiply(3,5)).to eq('the answer is 15') }
end
describe('#square') do
it { expect(subject.square(9)).to eq('the answer is 81') }
it { expect(sub... | true |
0c14d66c1d48648b44d60985653c25d29b7b3444 | Ruby | bonkydog/webhack | /app/models/duplex_stream_adapter.rb | UTF-8 | 1,263 | 2.6875 | 3 | [
"MIT"
] | permissive | require "rubygems"
require "logger"
require "activesupport"
require File.join(File.dirname(__FILE__), "../../lib/multiplex")
class DuplexStreamAdapter
include Multiplex
def initialize(coming_down, coming_up, going_down, going_up)
@coming_down = coming_down
@coming_up = coming_up
@going_down = goi... | true |
4cf3d61cd9f6af304133d08d17730499b64ca339 | Ruby | craig-suess/my_all | /lib/my_all.rb | UTF-8 | 436 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def my_all?(collection)
i = 0
block_return_values = [] ;
while i < collection.length
block_return_values << yield(collection[i]) ; #push each index of the old array to the new array when the given block is true
i += 1 ;
end
if block_return_values.include?(false)
... | true |
bb8200b9e55896ce44f50a91ddbccae4fc5c92a0 | Ruby | samesystem/active_graphql | /lib/active_graphql/client/actions/action/format_outputs.rb | UTF-8 | 1,059 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module ActiveGraphql
class Client
module Actions
class Action
# converts ruby object in to grapqhl output string
class FormatOutputs
def initialize(outputs)
@outputs = outputs
end
def call
Array.wrap(output... | true |
89d750378b1b16cc5620b00f96e9edf88ca5154e | Ruby | Bodhisattva2-0/development_task | /source/culini/db/seeds.rb | UTF-8 | 1,675 | 2.8125 | 3 | [] | no_license | #seeding customers
customer_1 = {:first_name => "Dean", :last_name => "Martin", :email => "dean.martin@culini.com"}
customer_2 = {:first_name => "Buddy", :last_name => "Rich", :email => "buddy.rich@culini.com"}
customer_3 = {:first_name => "Miles", :last_name => "Davis", :email => "miles.davis@culini.com"}
customer_4 =... | true |
4e07960fe4cc1175e2da0bf778c16e2862e459cd | Ruby | gdallen/pinkies | /features/step_definitions/read_zip_steps.rb | UTF-8 | 1,395 | 2.671875 | 3 | [] | no_license | Given /^zip file "(.*?)"$/ do |zip_filename|
@zip_reader = Zip_Reader.new zip_filename
end
When /^the zip file is read$/ do
@zip_reader.read_files
end
Then /^I should find file "(.*?)"$/ do |filename|
@zip_reader.filenames.include? filename
end
Then /^I should find (\d+) files inside the zip$/ do |arg1|
@zip... | true |
cb6430d8490e130d2ae11100a547dd140e5ea8f0 | Ruby | sheru94/W3D2 | /question_follow.rb | UTF-8 | 2,071 | 2.8125 | 3 | [] | no_license | require_relative 'orm'
require_relative 'User'
class QuestionFollows
attr_accessor :question_id, :user_id
def initialize(options)
@id = options['id']
@question_id = options['question_id']
@user_id = options['user_id']
end
def create
raise 'already exists' if @id
name = QuestionsDatabase.... | true |
8d13458bcce321340af6274ca09b34cf3ae0cbb9 | Ruby | ragmay/coin.rb | /task_4_4.rb | UTF-8 | 159 | 2.96875 | 3 | [] | no_license | if rand(11) == 10
puts 'Монета встала на ребро'
elsif rand(2) == 1
puts 'Выпала решка'
else
puts 'Выпал орел'
end
| true |
56ab7aa24e623b3d9d2426d18edbead80a2508b7 | Ruby | 10kh-at-rb/appacademy_curriculum_followup | /w2d5/lib/array.rb | UTF-8 | 1,048 | 3.625 | 4 | [] | no_license | class Array
def my_uniq
output = []
self.each do |el|
if !output.include?(el)
output << el
end
end
output
end
def two_sum
output = []
self.each_with_index do |el, i|
(i...self.length).each do |j|
output << [i, j] if self[i] + self[j] == 0
end
... | true |
41118082c5276ad40b60c7c70261c8c0b6e30e78 | Ruby | dave-slash-null/depot | /app/models/cart.rb | UTF-8 | 754 | 2.875 | 3 | [] | no_license | class Cart < ActiveRecord::Base
has_many :line_items, dependent: :destroy
def add_product(product_id)
current_item = line_items.find_by(product_id: product_id)
if current_item
current_item.quantity += 1
else
current_item = line_items.build(product_id: product_id)
end
return current_item
end
def t... | true |
98bcfa9a373ebe82a98c0a4c50bcbc2008a17eed | Ruby | keitheous/toy_robot_take_2 | /spec/board_spec.rb | UTF-8 | 1,236 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
RSpec.describe Board do
describe ".initialize" do
context 'creating instance without max_x and max_y limit params' do
board = Board.new
it 'returns 5 as maximum X navigation axis' do
expect(board.max_x).to eq(5)
end
it 'returns 5 as maximum Y navigation axi... | true |
8179896fab623ec77d68fb6c84fda6b40d9f791d | Ruby | edgecase/teststudio | /labs/greed/spec/models/computer_player_spec.rb | UTF-8 | 4,766 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe ComputerPlayer do
describe "its validations" do
it { should validate_presence_of(:strategy) }
it { should validate_presence_of(:score) }
it { should validate_numericality_of(:score) }
end
it "has a valid factory" do
player.should be_valid
end
let(:player) { Fa... | true |
1c8fe7fc6f74731241bc43fe32103c0a0ebf54c7 | Ruby | pangea-project/pangea-tooling | /lib/merger/branch_sequence.rb | UTF-8 | 3,704 | 2.828125 | 3 | [] | no_license | # frozen_string_literal: true
#
# Copyright (C) 2014-2016 Harald Sitter <sitter@kde.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your... | true |
911c264728e0fc9fc55eb3b29c4837bf924be47b | Ruby | alverad-katsuro/tic_tac_toe | /defenses/deadly_threats.rb | UTF-8 | 461 | 2.84375 | 3 | [] | no_license | class Defense
def self.avoid_deadly_threat game
return true if avoid_horizontal_deadly_threat game
#return true if avoid_vertical_deadly_threat
#return true if avoid_diagonal_deadly_threat
end
private
def self.avoid_horizontal_deadly_threat game
for row in game do
if (row.count 1) == 2 ... | true |
5abfa988b89514f5478565ae4719924efd93373b | Ruby | deven9229/Rubyprograms | /for_loop.rb | UTF-8 | 95 | 2.90625 | 3 | [] | no_license | friends = ["Kevin", "Karen", "Oscar", "Angela", "Andy"]
for index in 0..5
puts index
end
| true |
c185ab581060a9a7d63ebc493fbb4af8278b95d8 | Ruby | ministryofjustice/prison-visits-2 | /app/models/prisoner_validation.rb | UTF-8 | 566 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-proprietary-license"
] | permissive | class PrisonerValidation
UNKNOWN = 'unknown'.freeze
PRISONER_NOT_EXIST = 'prisoner_does_not_exist'.freeze
include ActiveModel::Validations
validate :active_prisoner_exists
def initialize(prisoner)
self.prisoner = prisoner
self.api_error = false
end
private
attr_accessor :prisoner, :... | true |
225c2d66fcd1175fa7aa926bb741db0395a018f5 | Ruby | wbray/chutney | /lib/chutney/linter/missing_feature_name.rb | UTF-8 | 455 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'chutney/linter'
module Chutney
# service class to lint for missing feature names
class MissingFeatureName < Linter
MESSAGE = 'All features should have a name'.freeze
def lint
features do |file, feature|
name = feature.key?(:name) ? feature[:name].strip : ''
next unless n... | true |
8817a1009e966723cedb662945bb4192b91ea76f | Ruby | pida42/unraid-youtube-dl | /root/usr/sbin/make-mvid-nfo.rb | UTF-8 | 429 | 2.515625 | 3 | [] | no_license | #!/usr/bin/env ruby
v1 = ARGV[0]
Dir.glob("#{v1}/*.*").each do |file|
nfo = File.dirname(file) + "/" + File.basename(file, ".*") + ".nfo"
artist, title = File.basename(file, ".*").split(' - ')
next if File.exists?(nfo)
puts "Creating nfo for #{title} - #{artist} of type musicvideo"
file = File.open(nfo, 'w')... | true |
0f10cf9541f40d73062ce2de27c3f45c8dc8b52d | Ruby | IlyaMur/ruby_learning | /RubyRush_school/lesson12/human.rb | UTF-8 | 596 | 3.609375 | 4 | [] | no_license | require_relative 'human_methods'
human1 = Human.new('Илья','Евгеньевич', 30)
human2 = Human.new('Сергей','Петрович', 65)
human3 = Human.new('Иван','Иванович', 20)
human1.set_fav_movie = 'Челюсти'
human2.set_fav_movie = 'Берегись автомобиля'
human3.set_fav_movie = 'Парк Юрского периода'
human1.gets_name
puts "С люби... | true |
735daac198c2286b8093a7e27fdb72b23bcb1db2 | Ruby | realestate-com-au/blobby | /lib/blobby/fake_success_store.rb | UTF-8 | 856 | 2.5625 | 3 | [] | no_license | # frozen_string_literal: true
require "blobby/key_constraint"
module Blobby
# A BLOB store that is always successful.
#
class FakeSuccessStore
def available?
true
end
def [](key)
KeyConstraint.must_allow!(key)
StoredObject.new
end
# Handle to an object in the store.
... | true |
b9d6abfb784c5b14031bc3e2cf33fc7e990afa2b | Ruby | Dinesh6/practice | /prog10.rb | UTF-8 | 1,142 | 3.171875 | 3 | [] | no_license |
##private method
class User
def initialize(name,address,phone,email)
@name=name
@address=address
@phone=phone
@email=email
end
end
class Account < User
@@count = 0
def initialize(name,address,phone,email,accountno,type,balance)
super(name,address,phone,email)
@accountno=accountno
@type=type
@bala... | true |
5d79a91e9066376e5308c0305c5e677773d05042 | Ruby | asenovm/ruby-retrospective-1 | /solutions/03.rb | UTF-8 | 9,853 | 3.375 | 3 | [] | no_license | require 'bigdecimal'
require 'bigdecimal/util'
class Product
attr_reader :name, :price, :discount
def initialize(name, price, discount)
Validate.product_name_length(name)
Validate.product_price(price)
@name = name
@price = price.to_d
@discount = DiscountUtil.get_discount_instance(discount)
end... | true |
061c982588ece81cc0cf4e9702198e04cfd00c0e | Ruby | rixth/rspec-launchpad | /lib/rspec-launchpad/reporter.rb | UTF-8 | 1,810 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'rspec/core/formatters/base_formatter'
require 'launchpad/device'
module RSpec
module Launchpad
class Reporter < RSpec::Core::Formatters::BaseFormatter
def initialize(output)
@x = 0
@y = 0
@device = ::Launchpad::Device.new
clear_all
super
end
def... | true |
f82013e9519f50c4d13bb32ee347a17bd13d561b | Ruby | terravitae/octomaps | /spec/services/map_spec.rb | UTF-8 | 7,263 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Map do
let(:country_options) { { :displayMode => 'region',
:region => 'world',
:legend => 'none',
:colors => ['FF8F86', 'C43512']} }
let(:city_options) { { :displayMode => 'markers',
... | true |
89b140829e03c26e8f6bf9acf6cd0383677bde4b | Ruby | sbcreates/reinforcement_tdd_simon | /simon_says.rb | UTF-8 | 248 | 3.65625 | 4 | [] | no_license | def echo(string)
string
end
def shout(string)
string.upcase
end
def repeat(string, num)
words = "#{string} " * num
words.strip
end
def start_of_word(string, num)
string[0..(num-1)]
end
def first_word(string)
string.split.first
end
| true |
bb0a4330a24889fd48f2e343354ef862cf421395 | Ruby | DrJid/Second-Run | /spec/requests/user_pages_spec.rb | UTF-8 | 5,322 | 2.546875 | 3 | [] | no_license | require 'spec_helper'
describe "UserPages" do
subject { page }
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
# FactoryGirl.create(:user, email: "index@grinnell.edu")
# FactoryGirl.create(:user, name: "Bob", email:"bob@examp.com")
# FactoryGirl.create(:us... | true |
f47a9ed183433f77cf7ce8bbcc25c46269441817 | Ruby | maeda5206/mrubyc | /sample_ruby/func_sample03.rb | UTF-8 | 71 | 3.390625 | 3 | [
"BSD-3-Clause"
] | permissive |
def add(a,b)
c = a + b
puts c
return c
end
x = add(3,4)
puts x
| true |
7fb4036e482b66d2a65e5237ceb3a71eafb09928 | Ruby | cxn03651/writeexcel | /examples/stats.rb | UTF-8 | 1,770 | 3.25 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/ruby -w
# -*- coding: utf-8 -*-
###############################################################################
#
# This is a simple example of how to use functions with the
# WriteExcel module.
#
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
#
# original written in Perl by John McNamara
# c... | true |
6f64a6169c78973fdabe59c9088aec6d0f78f3f3 | Ruby | digital-science/baton | /lib/baton/consumer_manager.rb | UTF-8 | 2,258 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require "baton/logging"
module Baton
class ConsumerManager
include Baton::Logging
attr_accessor :consumer, :channel, :exchange_in, :exchange_out
# Public: Initialize a ConsumerManager and adds itself as an observer to the consumer.
#
# consumer - An instance of Baton::Consumer
# channel - An... | true |
5d07f2d2064add537931be700e154ae4a4873006 | Ruby | NickMountjoy/learn_to_program | /ch12-new-classes-of-objects/party_like_its_roman_to_integer_mcmxcix.rb | UTF-8 | 523 | 3.328125 | 3 | [] | no_license | def roman_to_integer roman
output = 0
array = {"CM" => 900, "M" => 1000, "CD" => 400, "D" => 500, "XC" => 90, "C" => 100, "XL" => 40, "L" => 50, "IX" => 9, "X" => 10, "IV" => 4, "V" => 5, "I" => 1 }
last_val = 1_000_000_000_000_000
while roman.length > 0
array.each do |k, v|
if roman.upcase[0, 2]... | true |
5341f006f47540ad7a68c1417cec68830d25619f | Ruby | azessar/ruby_prac | /stairs.rb | UTF-8 | 403 | 3.75 | 4 | [] | no_license | # 1: 1
# 2: 3
# 3: 5
# 4: if you do 1 stair, 3 stairs, it's 6; if 3 stairs, 1 stair, it's 6; if 2 and 2, it's 6... so 18
# 5: 54
def stair_jumps(stairs)
return 0 if stairs < 0
return 1 if stairs == 0
return stair_jumps(stairs - 1) + stair_jumps(stairs - 2) + stair_jumps(stairs - 3)
end
p stair_jumps(1)
p... | true |
310f933245c6a838ae7e45e0723f014fe635e81f | Ruby | pbragamiranda-teaching/cookbook-day1-689 | /lib/scrape_test.rb | UTF-8 | 1,100 | 3.265625 | 3 | [] | no_license | # Ask a user for a keyword to search
# Make an HTTP request to the recipe’s website with our keyword
# Parse the HTML document to extract the first 5 recipes suggested and store them in an Array
# Display them in an indexed list
# Ask the user which recipe they want to import (ask for an index)
# Add it to the Cookbook... | true |
78b0d3c48c6a8f43eb0fb0442d9c39db540a8057 | Ruby | abratashov/bitmap_editor | /spec/bitmap_editor_spec.rb | UTF-8 | 1,328 | 2.78125 | 3 | [] | no_license | require 'spec_helper'
load 'app/bitmap.rb'
describe Bitmap do
let(:bitmap) {Bitmap.new}
before(:each) do
bitmap.init_new_image('I 3 3')
end
context 'Valid drawing' do
it 'Create image' do
expect(bitmap.image[0]).to eq 'OOO'
end
it 'Draw pixel' do
bitmap.draw_pixel('L 1 1 A')
... | true |
48513fb016f55279e189b5e2c39d00d992aba495 | Ruby | puppetlabs/puppetlabs-stdlib | /lib/puppet/functions/stdlib/powershell_escape.rb | UTF-8 | 818 | 3.046875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# @summary
# Escapes a string so that it can be safely used in a PowerShell command line.
#
# >* Note:* that the resulting string should be used unquoted and is not intended for use in double quotes nor in single
# quotes.
Puppet::Functions.create_function(:'stdlib::powershell_escape') ... | true |
a4a7dca88fe9caf394aa25591fb0f5cfde65b5be | Ruby | nucleotides/nucleotides-data | /bin/validate-s3-files | UTF-8 | 1,755 | 2.625 | 3 | [
"BSD-3-Clause-LBNL"
] | permissive | #!/usr/bin/env ruby
require 'fog/aws'
require 'colorize'
require 'inifile'
CREDS = {
'secret_key' => {env: 'AWS_SECRET_KEY', file: 'aws_secret_access_key'},
'access_key' => {env: 'AWS_ACCESS_KEY', file: 'aws_access_key_id'}
}
def fetch_credential(name)
if cred = ENV[CREDS[name][:env]]
return cred
end
... | true |
1568a23964eb26c3a1a48c7a4b5b69ad6bd5d5b3 | Ruby | mlibrary/middle_english_dictionary | /lib/middle_english_dictionary/collection/ms_names.rb | UTF-8 | 766 | 2.59375 | 3 | [] | no_license | require "nokogiri"
require "delegate"
require "middle_english_dictionary/bib/ms_full"
module MiddleEnglishDictionary
module Collection
class MSNames < SimpleDelegator
def initialize
@ms = {}
__setobj__(@ms)
end
def self.new_from_nokonode(nokonode)
msnames = new
... | true |
4a96e5a5170bece0415021755bf0afb1992627c0 | Ruby | Leon-Mbegera/bubble_sort | /bubble_sort.rb | UTF-8 | 252 | 3.578125 | 4 | [] | no_license | def bubble_sort(arr)
n = arr.length
loop do
swapped = false
(n - 1).times do |i|
if arr[i] > arr[i + 1]
arr[i], arr[i + 1] = arr[i + 1], arr[i]
swapped = true
end
end
break unless swapped
end
arr
end
| true |
89c2f711fa5ec1dd590d6d9aafc845368a35da15 | Ruby | jayphodges/job-tracker | /app/models/company.rb | UTF-8 | 508 | 2.5625 | 3 | [] | no_license | class Company < ApplicationRecord
validates :name, presence: true, uniqueness: true
has_many :comments
has_many :contacts
has_many :jobs
def self.top_three_by_interest
Company.all.sort_by do |company|
company.jobs.average(:level_of_interest)
end.last(3).reverse
end
def average_interest
... | true |
3ca75f2d763ca36acceca6583301311d5119dc2e | Ruby | ryanakuhl/Bike-Affiliate-Miner | /brownell.rb | UTF-8 | 531 | 2.84375 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
items = Array.new
prices = Array.new
doc = Nokogiri::HTML(open("http://www.brownells.com/optics-mounting/scopes/rifle-scopes/bushnell-banner-riflescopes-prod56933.aspx"))
items = doc.xpath("//span[contains(@itemprop,'name')][not(@style)]/text()").collect {|node| node.tex... | true |
c5561d17044289aba672df671bb0428ce8277912 | Ruby | jimoleary/mongo-jira | /lib/mongo/jira/config.rb | UTF-8 | 2,934 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'openssl'
begin
require 'Base64s'
rescue LoadError
module Base64
def decode64(str)
str.unpack('m0').first
end
def encode64(bin)
[bin].pack('m0')
end
end
end
require 'digest'
require 'mongo/jira/config_exception'
module Mongo
module Jira
class Config
CFG_FILE="#{EN... | true |
1e580103924494db2907fb580b1119980830c461 | Ruby | trizen/sidef | /scripts/Tests/array_and_hash_lookup.sf | UTF-8 | 1,124 | 3.625 | 4 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
#
## Test array and hash lookups
#
var a = %w(a b c d e f)
var h = Hash(
a => 1,
b => 2,
c => 3,
d => 4,
)
assert_eq(a[0], 'a')
assert_eq(a[3], 'd')
assert_eq(a[-1], 'f')
assert_eq(h{:a}, 1)
assert_eq(h{:c}, 3)
assert_eq(h{:d}, 4)
class Foo(k,i) {
method to_s {
k
}... | true |
85b512ed2e08aaae61821ea7fddbc8da4fe1fe7f | Ruby | Archeia/iek | /lib/space_box/vis_pos.rb | UTF-8 | 403 | 2.546875 | 3 | [] | no_license | #
# EDOS/lib/class/sprite.rb
# by IceDragon
# dc 22/06/2013
# dm 22/06/2013
# vr 1.0.0
module Mixin
module VisPos
#### experimental
### visible x|y (in short where the sprite is actually drawn)
def visx
self.x - self.ox
end
def visy
self.y - self.oy
end
def visx2
... | true |
a3d868141726fe7f3355ab972ef74accb20daf61 | Ruby | egutter/hotel_dashboard | /test/models/resort_stats_test.rb | UTF-8 | 2,027 | 2.671875 | 3 | [] | no_license | require 'test_helper'
require 'minitest/autorun'
class ResortStatsTest < MiniTest::Unit::TestCase
def setup
@resort = Resort.new(Resort::IMPALA_CODE, 100, [])
@reservation_date = Date.today
@daily_reservations = [DailyReservation.new(10, Date.new(2013, 8, 7), 1000, 'USD', 1),
... | true |
cd21969c8ec2d328f4f20e6a2a8de9eafce6d80e | Ruby | araujofelipe/pocfoobarcardclient | /main.rb | UTF-8 | 1,628 | 2.65625 | 3 | [] | no_license | require 'rubygems'
require 'restfulie'
require 'sinatra'
class RequisicaoPagamento
attr_accessor :numeroCartao,:dataExpiracao,:valor
def initialize(numeroCartao="00", dataExpiracao="00/00", valor=0.0)
@numeroCartao= numeroCartao
@dataExpiracao= dataExpiracao
@valor= valor
end
def to_xml
... | true |
358ba266e09a08832d7e1f286c26bf96ba661e8c | Ruby | MoDReD/kp_api | /lib/kp_api/global_search.rb | UTF-8 | 1,143 | 2.515625 | 3 | [
"MIT"
] | permissive | module KpApi
class GlobalSearch < Agent
attr_accessor :keyword, :url
def initialize(keyword)
@keyword = URI.encode(keyword)
@url = "#{DOMAINS[:api]}#{METHODS[:search_global][:method]}?#{METHODS[:search_global][:keyword]}=#{@keyword}"
@json = json
unless status
raise Ap... | true |
cb354f5e64be23f38e9da65f35a222c2214df0f8 | Ruby | venkataramana/Jquery-examples | /Ruby only/practice/whileloop.rb | UTF-8 | 196 | 3.34375 | 3 | [] | no_license | i=0
family=["amma","nanna","thatayya","nannamma","chelli","nenu"]
temp=[]
k= family.length
while i<k
puts family[i]
break if family[i]=="chelli"
i=i+1
end
| true |
ac0d6b549411cb3c488b623c0bb71a32454a21ac | Ruby | MagneticRegulus/Back-End-Prep-100-Ruby-Basics | /arrays/2_more_than_once.rb | UTF-8 | 431 | 4.8125 | 5 | [] | no_license | # Exercise: Select 'fish' and 'lizard' from pets at the same time, assign the
# return value to a variable named my_pets, then print the value of my_pets.
pets = ['cat', 'dog', 'fish', 'lizard']
my_pets = pets.select { |pet| pet == 'fish' || pet == 'lizard' }
puts "I have a pet #{my_pets[0]} and a pet #{my_pets[1]}!"... | true |
82be4c3ae80962fa42ec2b6e162564eb9d58a0bd | Ruby | Kinselan/myflix | /spec/models/video_spec.rb | UTF-8 | 2,811 | 2.625 | 3 | [] | no_license | require 'spec_helper'
describe Video do
# Do not need to test this, because you don't own the rails code
# it "saves itself" do
# video = Video.new(title:'The Big Short', description: 'You better believe it will not be long enough!')
# video.save
# expect(Video.first).to eq(video)
# end
it { shoul... | true |
dc90f55db663e68bc572bd3fdc4ebf5012db5369 | Ruby | Montblanc159/exo-ruby-s2j2 | /spec/02_jean_mich_trade_spec.rb | UTF-8 | 253 | 2.65625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../lib/02_jean_mich_trade'
describe "it decides of the best days to buy and sell actions" do
it "should return [1, 4]" do
expect(day_trader([17, 3, 6, 9, 15, 8, 6, 1, 10])).to eq([1, 4])
end
end
| true |
fcaa538fbf699d564bccf34970017bdc130a15be | Ruby | sydra08/cartoon-collections-v-000 | /cartoon_collections.rb | UTF-8 | 1,048 | 3.625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # first attempt 6/13/17
# def roll_call_dwarves(arr)
# arr.each_with_index do |name,index|
# puts "#{index+1} #{name}"
# end
# end
#
# def summon_captain_planet(arr)
# arr.collect do |name|
# "#{name.capitalize}!"
# end
# end
#
# def long_planeteer_calls(arr)
# arr.find {|call| call.length > 4} ? true... | true |
a4684d48692916bc135dffca3e1cc61855bab279 | Ruby | jas-meyer/ruby_projects | /fundamentals/animals/lion.rb | UTF-8 | 391 | 3.40625 | 3 | [] | no_license | require_relative 'mammal'
class Lion < Mammal
def initialize
super
@health += 20
end
def fly
@health -= 10
self
end
def attack_town
@health -= 50
self
end
def eat_humans
@health += 20
self
end
def display_health
puts "This is a lion"
super
self
end
end
lion1 = Lion.new.attack_to... | true |
fd30c14f0563d062bb34388c369839cfa0401c4e | Ruby | taw/project-euler | /euler_122.rb | UTF-8 | 838 | 3.171875 | 3 | [] | no_license | #!/usr/bin/env ruby1.9
# raise 'Slow as fuck'
seen = {}
v122 = {1 => 0}
sets = [[1]]
target = 200
# Binary multiplication takes <= 2 * log2(n) + c, amirite?
# Therefore I pressume result <= 15
while true
puts "#{sets.size} / #{v122.keys.size}"
sets.dup.each{|set|
set.each{|a|
set.each{|b|
sum... | true |
88f3a09b6cb5fa077287fe44a5f459426eb52a4c | Ruby | Tolvic/oystercard-challenge | /lib/station.rb | UTF-8 | 374 | 3.0625 | 3 | [] | no_license | class Station
attr_reader :zone
def initialize(zone = 1)
@min_fare = 5
@zone = zone
end
def touch_in(card)
raise('Insufficient funds.') unless card.check_balance >= @min_fare
card.journey_start(self)
card.in_journey = true
end
def touch_out(card)
card.deduct(@min_fare)
card.jo... | true |
f864e30f9d8515880ca9a1f97ddbe03f6013fc5b | Ruby | ireneyiu/algorithms | /arrays-strings/even-occuring-element.rb | UTF-8 | 454 | 4.34375 | 4 | [] | no_license | =begin
Given an integer array, one element occurs even number of times and all others have odd occurrences.
Find the element with even occurrences.
=end
def find_even_occurence(array)
occurences = {}
array.each do |element|
occurences[element] = 0 unless occurences[element]
occurences[element] += 1
end
o... | true |
be8efc2290067194f4868ccbd5b85bb5819ec5eb | Ruby | sabtain93/rb_101_small_problems | /easy_6/09.rb | UTF-8 | 991 | 4.21875 | 4 | [] | no_license | =begin
# Problem:
- Input: an array and a search value
- May be an empty array
- Output: Boolean
- true if the search value is present in the given array
- false if the search value is not present in the given array
- if nil is given as a search value, and an empty array is given, return false
- do not use th... | true |
d92b1702e1a6ba2eee80061f0402cac41b8d86b9 | Ruby | jaganthoutam/adop-sensu | /resources/plugins/connectivity/check-connectivity.rb | UTF-8 | 1,913 | 2.765625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# - Connectivity Checker
# -> Host/ports to check are defined by data bag "connectivity".
# -> Checks are templated out on chef client run to save on API calls.
#
require 'socket'
require 'timeout'
require 'workers'
# Connectivity checks
connectivity_checks = [
{:port=>"22", :host=>"10.0.1.5",... | true |
cbce7aa4086773a1d7c46af69e6f808b79a5a41d | Ruby | dashinfall3/tic_tac_WOAH | /app/controllers/index.rb | UTF-8 | 1,713 | 2.703125 | 3 | [] | no_license | get '/' do
erb :index
end
post '/login' do
@player = Player.find_by_email(params[:email])
if @player && @player.authenticate(params[:password])
session[:player_id] = @player.id
redirect "/arena"
else
@errors = "yo we got problems"
erb :index
end
end
post '/signup' do
@player = Player.new(p... | true |
c0625bbb92304e06e7d4b91740e366b47dd5bad3 | Ruby | tehillagarfinkel/object_oriented_ruby | /total_calculatable.rb | UTF-8 | 81 | 2.859375 | 3 | [] | no_license |
module TotalCalculatable
def subtotal
puts "Your subtotal is: "
end
end
| true |
cca10b0d998f13790040e357a7c171000bdb6748 | Ruby | CultureHQ/adequate_serialization | /test/attribute_test.rb | UTF-8 | 3,560 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'test_helper'
class AttributeTest < Minitest::Test
include AdequateSerialization::Attribute
class Model
def initialize(condition = true)
@condition = condition
end
def foo
'baz'
end
def foo?
@condition
end
end
def test_simple_... | true |
f71cf5c8014abdfde0a9574589384ff09b8e62be | Ruby | sassani134/colonel_moutarde | /app/models/player_number.rb | UTF-8 | 282 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
class PlayerNumber < ApplicationRecord
has_many :categories
has_many :games, through: :categories
def number_total
if number_low == number_high
" à #{number_low}"
else
" de #{number_low} à #{number_high}"
end
end
end
| true |
63d4f9f7cfe8a6801db3f51b7743a36f80189fcd | Ruby | Vostrikov2014/ruby_basic | /lesson_9/wagon_passenger.rb | UTF-8 | 365 | 3.3125 | 3 | [] | no_license | class WagonPassenger < Wagon
attr_reader :wagon_type, :free_place
def initialize(number, all_place)
super(number)
@wagon_type = 'passenger'
@all_place = all_place
@free_place = all_place
end
def take_place
raise 'All place busy' if @free_place.zero?
@free_place -= 1
end
def busy_... | true |
3fa3e117d941cd9cb2ad9192b6bd5cb85abe6187 | Ruby | toyhammered/blocipedia | /db/seeds.rb | UTF-8 | 1,613 | 2.9375 | 3 | [] | no_license | class CreateSeeds
def new_user(amount, email, role)
amount.times do
u = User.new(
email: email,
password: "fakefake",
password_confirmation: "fakefake",
confirmed_at: Time.now,
role: role
)
unless u.save
u.update_attributes(email: Faker::Internet.s... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.