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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
072a25394225cd17fa18b68e3bcc9b6e35c566ed | Ruby | nanma80/euler_project | /p126_150/p140/v1.rb | UTF-8 | 743 | 3.421875 | 3 | [] | no_license | require 'matrix'
def next_term(array, k)
dim = k + 1
array_first_terms = array[0..k]
m = Matrix.build(dim, dim) do |row, col|
(row + 1) ** col
end
fitted = (m.inverse * Vector.elements(array_first_terms)).to_a
array_first_terms + [polynomial(fitted, k + 2).to_i]
end
def polynomial(coef, n)
# coef... | true |
348e2069d2bad96949a09c6816863a69425f11b5 | Ruby | jakrzus/jobbyjobjob | /lib/jobby_job_job/stack_overflow_parser.rb | UTF-8 | 578 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'feedjira'
require 'jobby_job_job/job_parser'
class StackOverflowParser < JobParser
def initialize
end
def process(data)
data.map! { |item|
{
title: get_title(item.title),
description: sanitize_html(item.summary),
publish_date: item.published,
company: get_compa... | true |
9f2f94bb69dbc97cb1e27db0a176fdeffb874c47 | Ruby | EarthWormGym/chitter-challenge | /lib/peep.rb | UTF-8 | 904 | 2.875 | 3 | [] | no_license | require 'pg'
class Peep
attr_reader :id, :peep
def initialize(id:, peep:)
@id = id
@peep = peep
end
def self.all
if ENV['ENVIRONMENT'] == 'test'
connection = PG.connect(dbname: 'chitter_test_database')
p 'testing data'
else
connection = PG.connect(dbname: 'chitter_database... | true |
5c1a33bccf5d8d0f8d193772a82ce50e23772bd4 | Ruby | kscotteng/RubyPractice | /SpellNumber.rb | UTF-8 | 3,618 | 4.84375 | 5 | [] | no_license | # this program will take a number from 0 - 100 and spell it out
def spellNumber(number)
# number has to be at least zero and can not be greater than 100
if number < 0 || number > 100
return 'Please enter a number between 0 and 100'
end
# number spelled out and returned as a string
numString = ''
one... | true |
43bbb8d721b36f38caea444c98c448488d2f871e | Ruby | Jon2041/Ruby_Book_1 | /exercises/exercise7.rb | UTF-8 | 225 | 3.546875 | 4 | [] | no_license | # What's the major difference between an Array and a Hash?
# An array stores data with an integer index starting at 0. A hash stores key-value
# pairs, so you can access data by finding the key, which can be any data type.
| true |
b31fe6381abece64c327c18022b28f1706aa51ec | Ruby | inertia186/cobblebot | /app/concerns/emotable.rb | UTF-8 | 1,549 | 2.515625 | 3 | [
"CC0-1.0"
] | permissive | module Emotable
extend Commandable
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
## Simuates /me
def emote(selector, message, options = {color: 'white', as: 'Server'})
return if selector.nil?
if !!(hover_text = options[:hover_text]) && hover_text.pre... | true |
a6c2b72c0cdca51f9e565ef146661d203d673c89 | Ruby | robisenberg/prime_finder | /benchmark/procedural_vs_functional_benchmark.rb | UTF-8 | 692 | 3.0625 | 3 | [] | no_license | require 'benchmark'
require_relative '../lib/prime_finder/procedural'
require_relative '../lib/prime_finder/functional'
LABEL_WIDTH = 12
def benchmark_procedural_vs_functional_prime_finding(quantity:)
puts "\n#{quantity} prime numbers...\n\n"
Benchmark.bmbm(LABEL_WIDTH) do |benchmark|
benchmark.report('proce... | true |
e016353f511e12092bd8a597ec2cd68557892da5 | Ruby | judis007/rubylibrarian | /app/models/book.rb | UTF-8 | 397 | 2.828125 | 3 | [] | no_license | class Book < ApplicationRecord
validates :name, :author, :synopsis, presence: true
before_save :capitalize_book_name, :capitalize_book_author, :capitalize_book_synopsis
def capitalize_book_name
self.name.capitalize!
end
def capitalize_book_author
self.author.capitalize!
end
... | true |
3a637b649f8765ecc817d36d891a62f2a5cbea3f | Ruby | mikedillion/citygram | /app/models/plugins/geometry_validation.rb | UTF-8 | 1,086 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'geo_ruby/geojson'
module Citygram
module Models
module Plugins
module GeometryValidation
module InstanceMethods
FEATURE_TYPES = %w(
Point
MultiPoint
LineString
MultiLineString
Polygon
MultiPolygon
... | true |
8ccbc90c0f2b3f3233674162066a8873693deefd | Ruby | pinkvelociraptor/Zendesk_is_cool | /grade.rb | UTF-8 | 618 | 3.390625 | 3 | [] | no_license | class Grade
attr :numeric
attr :str
include Comparable
def initialize(str)
str.upcase =~ /([A-F])(\+|-)?/
grade = $1 # A
mod = $2 # +
num = case grade
when 'A'
0.5
when 'B'
1.5
when 'C'
2.5
when 'D'
3.5
when 'E'
4.5
when 'F'
5.... | true |
09a53b0576b62d644844740b4f2ccf9c3230aa2b | Ruby | jsiny/small-projects | /leetcode/121-1.rb | UTF-8 | 414 | 3.8125 | 4 | [] | no_license | # https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
def max_profit(prices)
return 0 if prices == prices.sort.reverse
result = 0
prices[0...-1].each_with_index do |buying_price, i|
selling_price = prices[i + 1..-1].max
profit = selling_price - buying_price
result = profit if profit > ... | true |
3eea5e006f4115a6be55ec5e9791c7d20364b6ac | Ruby | Van-Ausburn/Launch_School | /RB100/variable_scope/my_value7.rb | UTF-8 | 159 | 3.9375 | 4 | [] | no_license | # my_value7.rb
a = 7
array = [1, 2, 3]
array.each do |element|
a = element
end
puts a
# answer => 3 3 was the iteration through the array, making a = 3
| true |
2d9057897c81b4cb180626dafd16a3adf3c98ed2 | Ruby | busteraph/test_simundia | /collaborator.rb | UTF-8 | 327 | 2.609375 | 3 | [] | no_license | class Collaborator
attr_accessor :first_name, :last_name, :email, :scope_id
def initialize(first_name, last_name, email, scope_id)
self.first_name = first_name
self.last_name = last_name
self.email = email
self.scope_id = scope_id
end
def to_csv
[first_name, last_name, email, scope_id]
end... | true |
22cbd5bcd08550409bc81e047a70904ca1433999 | Ruby | handacg/landing-page | /app/services/twitter_lead.rb | UTF-8 | 2,832 | 2.953125 | 3 | [] | no_license | require 'pry'
require 'rubocop'
require 'dotenv'
require 'twitter'
require 'json'
Dotenv.load
class TwitterLead
def initialize
puts "Bonjour"
@client = Twitter::REST::Client.new do |config|
# Utiliser DOTENV
config.consumer_key = ENV["TWITTER_API_KEY"]
confi... | true |
caa3737a37d264d1f0c3c12f235babc095ecb096 | Ruby | seamile/PyTutor | /v5-unity/example-code/ruby/inst-class-vars-complex.rb | UTF-8 | 1,177 | 3.75 | 4 | [
"MIT"
] | permissive | # adapted from http://rubylearning.com/satishtalim/ruby_constants.html
# p057mymethods2.rb
# variables and methods start lowercase
$glob = 5 # global variables start with $
class TestVar # class name constant, start uppercase
@@cla = 6 # class variables start with @@
CONST_VA... | true |
db86d160af7be56e76dfcc1f3d6856987e3a8831 | Ruby | jott7767/read-today | /app/helpers/activities_helper.rb | UTF-8 | 1,336 | 2.546875 | 3 | [] | no_license | module ActivitiesHelper
def underscore_title(activity)
activity.gsub(" ", "_").underscore
end
def viewable?(month)
if admin_signed_in?
true
else
clickable_months.include?(translate_month(month))
end
end
def months_for_select
months = [
["January", 1],
["Februar... | true |
d995967108bb0e98e3a3d726238397e43d695edb | Ruby | Svatok/todo_app | /app/controllers/v1/items_controller.rb | UTF-8 | 2,794 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
module V1
class ItemsController < ApplicationController
before_action :authenticate_user!
before_action :set_todo
before_action :set_todo_item, only: %i(show update destroy)
def_param_group :path_params do
param :id, :number, required: true
param :todo_id, :... | true |
656732d75dcce2d4e500a2fe5926fd4abbddfe88 | Ruby | owenabbott/ruby-enumerables-introduction-to-map-and-reduce-lab-chicago-web-021720 | /lib/my_code.rb | UTF-8 | 880 | 3.328125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # My Code here....
def map_to_negativize(source_array)
new_array = []
for i in source_array
new_array.push(i*-1)
end
return new_array
end
def map_to_no_change(source_array)
new_array=source_array
return new_array
end
def map_to_double(source_array)
new_array=[]
for i in source_array
new_array.push(i*2... | true |
cf8de6a11c0f21286a4a22c715662a40e9c45eb2 | Ruby | MerlinEvgeniy/coursesRuby | /task1.rb | UTF-8 | 302 | 3.453125 | 3 | [] | no_license | ARGV[0]
str = ARGV.join
if str.ascii_only? != true
exit
end
if ARGV.size >= 1 && ARGV.size <= 10000
original_string = ARGV.join
string = original_string.downcase.scan(/[A-Za-z0-9]/)
reverse_string = string.reverse
if string == reverse_string
puts "YES"
else
puts "NO"
end
end
| true |
2b587c29e9b7bb57886b9d05638fc1358ea75123 | Ruby | cjhhh/tic-tac-toe-rb-v-000 | /lib/tic_tac_toe.rb | UTF-8 | 1,846 | 4.1875 | 4 | [] | no_license | require 'pry'
WIN_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
]
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts ... | true |
f4a51344403fd25c86d515bdd25e9e708b1cc2de | Ruby | greggersh/flixated | /lib/flixated/catalog.rb | UTF-8 | 5,827 | 2.65625 | 3 | [
"MIT"
] | permissive | module Flixated
class Client
# Returns the matching titles in relevance order and
# total number of results.
# Valid parameters are:
# :term The word or term for which to search in the catalog. The
# method searches the title and synopses of catalog titles
# ... | true |
2594a663cbb701ada8fa30c84e7395e5f9bcc949 | Ruby | lac417/kwk-l1-hash-iteration-mini-lab-kwk-students-l1-nyc-080618 | /summer_olympics_hash.rb | UTF-8 | 1,089 | 4.25 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def create_olympics_hash
{Sydney: "2000", Athens: "2004", Beijing: "2008", London: "2012"}
end
# Implement this method so that it returns a hash with the data provided on README.md
def add_a_key_value_pair
new_hash = create_olympics_hash
new_hash[:Atlanta] = "1996"
new_hash
end
# Implement this method so th... | true |
2d1e19a402bce2ec09a5b15b4dc93c78a0881d82 | Ruby | vladcranga/COM1001---Semester-2-Project | /spec/unit/privileges_spec.rb | UTF-8 | 726 | 2.5625 | 3 | [] | no_license | require "rspec"
require "rack/test"
require_relative "../spec_helper"
RSpec.describe Privilege do
include Rack::Test::Methods
describe "#load" do
it "loads the privilege into a new instance of Privilege object" do
privilege = described_class.new
params = "Mentee"
privilege.load(params)
... | true |
d6a7e5828d402dc80a4ad2be6362e2e2d5743e66 | Ruby | chestergarett/ruby_activity | /lesson_1/age.rb | UTF-8 | 338 | 4.15625 | 4 | [] | no_license |
def get_age(age,number)
age.to_f+number.to_f
end
puts "How old are you?"
input = gets.chomp
25.times {print "-"}
puts
puts "In 10 years you will be"
puts get_age(input,10)
puts "In 20 years you will be"
puts get_age(input,20)
puts "In 30 years you will be"
puts get_age(input,30)
puts "In 40 years you will be"
puts ... | true |
31d02793b56d8aeef159ad7c2b5c322059c70add | Ruby | krismac/course_notes | /week_02/day_2/multiple_classes/multiple_classes_lesson/instrument.rb | UTF-8 | 251 | 3.09375 | 3 | [] | no_license | class Instrument
attr_reader :type
def initialize(type)
@type = type
end
def make_sound(title)
if @type == "piano"
return "Plink plonk... I'm playing #{title}!"
else
return "I'm playing #{title}!"
end
end
end
| true |
d3c217f72934347a098bb3e88fd690079d1c80d0 | Ruby | djafaar/HomeworkGG | /Modul1/Session2/Villain.rb | UTF-8 | 592 | 3.34375 | 3 | [] | no_license | require_relative 'Soldiers'
class Archer < Soldiers
def attack(enemy)
enemy.take_damage(@char_attack)
puts "#{@char_name} shoots an arrow at #{enemy.char_name} with #{@char_attack} damage"
end
end
class Spearman < Soldiers
def attack(enemy)
enemy.take_damage(@char_attack)
p... | true |
c568051c03b08673ba71d59942dd6c5bdab1c7c8 | Ruby | johndillon773/intro_to_programming | /the_basics/4.rb | UTF-8 | 111 | 2.8125 | 3 | [] | no_license | dates = [ 1939, 1941, 1949, 2017, 1920 ]
puts dates[0]
puts dates[1]
puts dates[2]
puts dates[3]
puts dates[4] | true |
08e3931acd9f6c38943d78b28518592228d25d55 | Ruby | turboladen/tailor | /lib/tailor/configuration.rb | UTF-8 | 7,683 | 2.609375 | 3 | [
"MIT"
] | permissive | require_relative '../tailor'
require_relative 'logger'
require_relative 'runtime_error'
require_relative 'configuration/style'
require_relative 'configuration/file_set'
class Tailor
# Pulls in any configuration from the places configuration can be set:
# 1. ~/.tailorrc
# 2. CLI options
# 3. Default opti... | true |
ba64a1e9d09465f32e995e2fd0714afcf45a78e2 | Ruby | cul/ldpd-hyacinth | /app/models/concerns/digital_object_concerns/purge_behavior.rb | UTF-8 | 2,113 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
# TODO: Delete this after ensuring that equivalent functionality is ported
module DigitalObjectConcerns
module PurgeBehavior
# extend ActiveSupport::Concern
# # Purges this object, performing cleanup in such a way that it's as if the object never existed.
# # A purge operat... | true |
5a16a6091181006ff78eb658e6d30699ac56ad4a | Ruby | mshwery/codex | /db/seeds.rb | UTF-8 | 3,005 | 2.96875 | 3 | [] | no_license | require 'nokogiri'
#require 'stopwords'
# def stopwords
# Terminology::STOPWORDS
# end
# def file
# File.read(Rails.root.join('public/2015/FY15_Tabular.xml')).to_s
# end
# def xml_doc
# Nokogiri::XML(file).to_s
# end
def get_text_node(node)
text = nil
if node and node.text
text = node.text
end
t... | true |
8b6bf986256919da06ea2ae5dd3cecde5a2a404b | Ruby | cauil/Cousera-ProgrammingLanguages | /week8/ruby_intro.rb | UTF-8 | 101 | 3.21875 | 3 | [] | no_license | class Hello
def my_first_method
puts "hello world"
end
end
x = Hello.new
x.my_first_method
| true |
cd4e4ef944446bf21f07393f0a0c3892629f3e74 | Ruby | AudreyJones/oo-cash-register-online-web-ft-021119 | /lib/cash_register.rb | UTF-8 | 1,867 | 4 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
# Note that a discount is calculated as a percentage off of the total cash register price
# (e.g. a discount of 20 means the customer receives 20% off of their total price).
# Hint #1: Keep in mind that to call an instance method ins... | true |
5792fc4c2e79650b479113cd953e04b885dd86ed | Ruby | ttonelli/rubyscape | /simpleoverlay.rb | UTF-8 | 3,039 | 3.109375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
require 'rubyscape'
#
# A class to create overlays by showing and hiding elements of an SVG file
# and taking snapshots. To implement a new overlay, simply extend this class
# and override the script method.
#
class SimpleOverlay < RubyScape
# Data
attr_accessor :count, :last
# Counters for la... | true |
11ed6fcc1d4e4b88afbb5504ac815456186c2418 | Ruby | fontcuberta/Ironhack-Week-1 | /Day-1/Examples/reduce.rb | UTF-8 | 106 | 3 | 3 | [] | no_license | cities = ["miami", "madrid", "barcelona"]
puts cities.reduce {|sum, x| (sum.length > x.length)? sum : x }
| true |
4f6d6dc8f6ff7ee25fa8daaf9c13da1ca248ecb3 | Ruby | dayne/chunker | /chunker | UTF-8 | 3,862 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'optparse'
require 'yaml'
KILO = 1024; MEGA = KILO * 1024; GIGS = MEGA * 1024
def size(s)
s = s
return "#{s/GIGS}G" if (s / GIGS) > 1
return "#{s/MEGA}M" if (s / MEGA) > 1
return "#{s/KILO}K" if (s / KILO) > 1
return "#{s}B"
end
copyright = "Copyright (C) 2008"
license = ""
opt... | true |
50997f078dc3a225a60278151a8a5ff22e3eff2c | Ruby | Abohte/match-it-up | /app/models/pair.rb | UTF-8 | 305 | 2.59375 | 3 | [] | no_license | class Pair < ApplicationRecord
has_many :matches, dependent: :destroy
has_many :students, through: :matches, source: :user
validates :date, presence: true
def future?
self.date > Date.today
end
def pretty_print
self.students.map{|student| student.full_name}.join(" , ")
end
end
| true |
c0412391b0b28f07d119401a2cd57b5dd1fb1083 | Ruby | Rambatino/teer | /spec/teer_spec.rb | UTF-8 | 10,362 | 2.921875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
RSpec.describe Teer do
it 'has a version number' do
expect(Teer::VERSION).not_to be nil
end
it 'creates an empty finding when no data' do
expect(Teer::Template.create([], [], '')).to eq(OpenStruct.new(data: nil, finding: nil))
end
context 'when looking at apples data' ... | true |
33e54a8456eb033919038856cf449fbece11a30a | Ruby | RobertoCarrilloAvila/shipments_tracking | /app/lib/tracking/fedex.rb | UTF-8 | 1,747 | 2.546875 | 3 | [] | no_license | class Tracking::Fedex
include Tracking::Fedex::Utils
def initialize(tracking_number)
@tracking_number = tracking_number
@fedex = Fedex::Shipment.new(fedex_credentials)
end
def request
request_handler
response = Tracking::Response.new(@details)
response.events.concat @events
return response
end
priv... | true |
9bcc7a6245f23e62dc6ac818fb094916adaa30f5 | Ruby | jpatel531/tictactoe | /spec/computer_spec.rb | UTF-8 | 1,400 | 3.203125 | 3 | [] | no_license | require 'computer'
describe Computer do
let(:computer) { Computer.new }
let(:player) {Player.new}
let(:board) {Board.new}
before do
computer.board = board
player.board = board
end
it 'can do what a player can do' do
expect(computer).to be_a Player
end
it 'is is identified by a O' do
expect(comput... | true |
6f115a267082a76d5045462fed89fc8992310b2a | Ruby | ichthala/tscripter | /spec/tscripter_spec.rb | UTF-8 | 5,183 | 2.75 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Tscripter do
it 'has a version number' do
expect(Tscripter::VERSION).not_to be nil
end
end
describe Tscripter::Runner do
let(:runner) { Tscripter::Runner.new }
describe "#go_with_args" do
it 'returns the expected error description' do
expect(runner.go_with_args())... | true |
405752011947e4ecea27fd46af2a4821013ce6e3 | Ruby | JamieSK/rock_paper_scissors | /models/game.rb | UTF-8 | 374 | 3.625 | 4 | [] | no_license | require_relative 'ring'
class Game
def self.play(move1, move2)
precedence = Ring.new(['rock', 'scissors', 'paper'])
if precedence.next(move1) == move2
return "Player 1 wins with #{move1.capitalize}!"
elsif precedence.previous(move1) == move2
return "Player 2 wins with #{move2.capitalize}!"
... | true |
9c0b741cb30b59b50a5297b73c24220f67f83480 | Ruby | eliotv/ruby | /Day01/ex02/name.rb | UTF-8 | 97 | 2.515625 | 3 | [] | no_license | first_name = "Eliot "
last_name = "vanHeumen"
full_name = first_name + last_name
print full_name
| true |
e397b44a01e3091e215e6f2376acd0b5c99b7ea4 | Ruby | nkrot/rufsl | /lesson.29/textspacer/verticalize | UTF-8 | 2,036 | 3.40625 | 3 | [] | no_license | #!/usr/bin/env ruby
# # #
#
#
require 'optparse'
OptionParser.new do |opts|
opts.banner = "
Convert the text to the format valid for feeding the text to CRF utils.
USAGE: #{File.basename($0)} [OPTIONS] text_file(s)
OPTIONS:
"
@add_tags = false
opts.on('--add-tags', 'add tags to each character') do
@add_... | true |
ccc60dde8afb041276efccfad57353176df3af7f | Ruby | ekluff/ping_pong | /lib/ping_pong.rb | UTF-8 | 318 | 2.78125 | 3 | [] | no_license | class Fixnum
define_method(:ping_pong) do
array_num = (1..self).to_a
array_num.map! do |number|
if number % 3 == 0 && number % 5 == 0
"PININININGGGG PONNNNNNNNNG!!!!?!"
elsif number % 3 == 0
"ping"
elsif number % 5 == 0
"pong"
else
number
end
end
end
end
| true |
b400a95bcd8ae228f09df41d86a163901ae8d309 | Ruby | keithiopia/feedback | /app/models/ticket.rb | UTF-8 | 1,400 | 2.703125 | 3 | [] | no_license | require 'uri'
class Ticket
include ActiveModel::Validations
attr_accessor :val, :user_agent, :url
# This is deliberately higher than the max character count
# in the front-end (javascript and maxlength in the markup),
# because certain browsers treat "\r\n" incorrectly as
# 1 character long.
FIELD_MAXIM... | true |
50beede75404725b122370edda372d2e4b0e710c | Ruby | satek/media-management | /app/models/media_item.rb | UTF-8 | 719 | 2.65625 | 3 | [] | no_license | class MediaItem < ActiveRecord::Base
validates :title, :description, :user_id, :type, presence: true
validate :type_correctness
belongs_to :user
delegate :name, to: :user, prefix: true
def self.type_descriptions
{
"Video" => "VideoItem",
"Web Link" => "LinkItem",
"Image" => "ImageIte... | true |
9a2b130f55723b0289e7ec2ce11e10f2497486da | Ruby | arseny-emchik/zifs | /lab2/lib/message.rb | UTF-8 | 157 | 2.84375 | 3 | [] | no_license | class Message
attr_accessor :state
attr_reader :content
def initialize(p)
@p = p
@content = [*1...@p].sample
@state = @content
end
end
| true |
d1c365be0ffb1d77043f8ea70972d110e979b2e1 | Ruby | Strompy/war_or_peace | /test/deck_test.rb | UTF-8 | 2,681 | 3.109375 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/card'
require './lib/deck'
# require 'pry'
class DeckTest < Minitest::Test
def test_it_exists
deck = Deck.new
assert_instance_of Deck, deck
end
def test_it_has_cards
card1 = Card.new(:diamond, 'Queen', 12)
card2 = Card.new(:spad... | true |
d0afb940e50326f5b32e943be035e34e59ad83a8 | Ruby | Domzzzzzz/MuseFinder | /app/helpers/application_helper.rb | UTF-8 | 410 | 2.75 | 3 | [] | no_license | module ApplicationHelper
# This helper calculates age from a user's DOB
def age(dob)
(Date.today - dob).to_i / 365
end
# Helper to display how long ago a post was created
def how_long_ago(post)
if post.created_at > Time.now.beginning_of_day
"Posted " + time_ago_in_words(post.created_at) + " ag... | true |
65a3b7f8d76e1cb449c8c9671bf4074fd57c4917 | Ruby | cjmarkham/param_check | /lib/param_check.rb | UTF-8 | 3,384 | 2.921875 | 3 | [
"MIT"
] | permissive | require "param_check/version"
require 'param_check/engine'
module ParamCheck
extend self
class ParameterError < StandardError; end
class MockController
include ParamCheck
attr_accessor :params
end
def param! name, options, &block
validate! name, params.try(:[], name), options
if block_giv... | true |
9904503188b5134f1e8179b87b4615a8c4a6d809 | Ruby | fred84/ruby-learning | /test/module_nesting_test.rb | UTF-8 | 2,084 | 3.046875 | 3 | [] | no_license | require 'minitest/autorun'
class ModuleNestingTest < Minitest::Test
class A
attr_accessor :log
def initialize
@log = []
end
def run
log << 'A'
super # will be handled via method_missing
end
def method_missing(name)
@log << 'missing at A'
end
end
class B <... | true |
2b2bc284770f761b40148c2662a079b4f5897155 | Ruby | davmckin/PEReporting | /data_parser.rb | UTF-8 | 1,063 | 3.296875 | 3 | [] | no_license | require 'csv'
class Delivery
attr_accessor :planet,
:shipment,
:crates,
:revenue,
:pilot,
:bonus
def initialize(destination:, what_got_shipped:, number_of_crates:, money_we_made:)
@planet = destination.downcase
@shipment = wha... | true |
88a91d17b73ff1fd25d4970d0b0a29895ac7d813 | Ruby | stormbrew/channel9 | /environments/ruby/simple_tests/029.regex-match.rb | UTF-8 | 222 | 2.75 | 3 | [
"MIT"
] | permissive | # needed for tagging to work
r = /^([^()#:]+)(\(([^)]+)?\))?:(.*)$/
m = r.match "zoop"
puts m.class
m = r.match "zoop:doop"
puts m[0], m.values_at(1, 3, 4)
m = r.match "zoop(woop):doop!"
puts m[0], m.values_at(1, 3, 4)
| true |
7e7e4fb095acd463a7ed9cf22d9b024b8736af12 | Ruby | jcreiff/exercism | /ruby/tournament/tournament.rb | UTF-8 | 1,460 | 3.328125 | 3 | [] | no_license | class Tournament
def initialize(results)
@results = results.split("\n").map { _1.split(';') }
@teams = {}
update_results
end
def tally
score_games(@results)
Scoreboard.display(@teams.values)
end
def self.tally(results)
Tournament.new(results).tally
end
private
def update_resu... | true |
59f9ca80b4cccbd031ab26f7b6be98b51f0fa906 | Ruby | ShelbyTV/shelby_gt | /lib/utils/nos_user_roll_type_fixer.rb | UTF-8 | 968 | 2.6875 | 3 | [] | no_license | # This was written to fix up all the old NOS users's roll properties so they are treated as user rolls in GT.
# Left checked in as demo code / in case it's useful in the near future.
#
# *Should only be used for DB repair/fixing*
#
# Usage:
# Dev::NosUserRollTypeFixer.fix!
#
module Dev
class NosUserRollTypeFixer
... | true |
f4bab46ef7b74e87c69a01a4cbc98162a6baac7e | Ruby | rvandervort/platform45 | /spec/lib/default_placement_strategy_spec.rb | UTF-8 | 671 | 2.546875 | 3 | [] | no_license | require 'spec_helper.rb'
describe DefaultPlacementStrategy do
let(:board) { Board.new(10) }
let(:ships) {[Ship.new("Ship5",5), Ship.new("Ship3",3), Ship.new("Ship2", 2)]}
let(:response) { DefaultPlacementStrategy.place(board, ships) }
describe "#place(board, ships)" do
it "places every ship" do
resp... | true |
a8e54305b5f9781f3d901fefb9b15f7ecee8e56c | Ruby | darrickpang/ruby-enumerables-hash-practice-emoticon-translator-lab-sfo01-seng-ft-042020 | /lib/translator.rb | UTF-8 | 921 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require "yaml"
def load_library(data)
hash = {}
files = YAML.load_file('./lib/emoticons.yml')
files.each do |emotions, symbols|
hash[emotions] = {:english => symbols[0], :japanese => symbols[1]}
end
return hash
end
def get_japanese_emoticon(file = "./lib/emoticons.yml", english)
data = ... | true |
e164f87e4f45b5ce64fc8ffc6bc30566472bf40c | Ruby | spacether/appacademy_daily | /w2d3/poker/spec/deck_spec.rb | UTF-8 | 1,227 | 3.09375 | 3 | [] | no_license | require 'deck.rb'
describe 'Deck' do
subject(:deck) { Deck.new }
context '#initialize' do
it "generates 52 cards" do
expect(deck.length).to eq(52)
end
it "creates 13 cards of each suit" do
clubs = deck.cards.select { |card| card.suit == :clubs }
spades = deck.cards.select { |card| c... | true |
6b08674c740a997461465213b1055a8f13bc2b01 | Ruby | lbeder/Eyes.Selenium.Ruby | /lib/applitools/base/test_results.rb | UTF-8 | 1,107 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | module Applitools::Base
class TestResults
attr_accessor :is_new, :url
attr_reader :steps, :matches, :mismatches, :missing, :exact_matches, :strict_matches, :content_matches,
:layout_matches, :none_matches
def initialize(steps = 0, matches = 0, mismatches = 0, missing = 0, exact_matches = 0, strict_... | true |
9c0eb53f74d69c9190c239d0c5ee290da21325d8 | Ruby | ANDRIANAIVOSOA/njara_fenitra_3 | /chiffre_de_cesar.rb | UTF-8 | 1,147 | 3.671875 | 4 | [] | no_license | def chiffre_de_cesar(text, cle)
asciiChiffre = []
textChiffe = ""
textString = text.to_s
for i in 0..textString.length-1
asciiChiffre[i] = textString[i].ord
if (["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]).include?(textString[i])
if asciiChiffr... | true |
3d76ca2df37bc509b054dc65de02328b7296b127 | Ruby | twodee/japanese | /adjective | UTF-8 | 557 | 3.171875 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative 'japanese'
adjectives = Japanese.adjectives
adjective = adjectives.find { |adjective| adjective.kana == ARGV[0] }
puts "is_i? #{adjective.is_i?}"
puts "is_na? #{adjective.is_na?}"
puts
puts "PRESENT"
puts adjective.is(true, true, false)
puts adjective.is(true, true, true)
puts ad... | true |
3ea3c693de95f74353f891025c7de8ab6737f66f | Ruby | katyjane8/night_writer | /test/translator_test.rb | UTF-8 | 1,903 | 3.3125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/translator'
require 'pry'
class TranslatorTest < MiniTest::Test
def test_it_exists
translate = Translator.new("text_in")
assert_instance_of Translator, translate
end
def test_braille_instance
translate = Translator.new("text_in")
... | true |
ef7827ec6d68aa4866d14ca5f005991de0a21dbe | Ruby | socketry/falcon | /examples/beer/config.ru | UTF-8 | 1,909 | 2.828125 | 3 | [
"LicenseRef-scancode-dco-1.1",
"MIT"
] | permissive | #!/usr/bin/env falcon --verbose serve -c
# frozen_string_literal: true
require 'rack'
require 'cgi'
def bottles(n)
n == 1 ? "#{n} bottle" : "#{n} bottles"
end
# Browsers don't show streaming content until a certain threshold has been met. For most browers, it's about 1024 bytes. So, we have a comment of about that ... | true |
e2acf6eefb0079196292d1ca7c94b65d78c0adff | Ruby | drewblas/magistrate | /spec/resources/rake_like_worker.rb | UTF-8 | 80 | 2.734375 | 3 | [
"MIT"
] | permissive | trap('USR1') {
puts 'Doing good'
}
while true do
puts '1'
sleep(3)
end
| true |
974322d80113d57ea2aec64807b27ff2f0dd2f4b | Ruby | huisun/ruby-exercise | /app/models/tweet_form.rb | UTF-8 | 548 | 2.53125 | 3 | [] | no_license | class TweetForm
include ActiveModel::Model
attr_accessor :currency_id
validates :currency_id, presence: true
def create
return false unless self.valid?
create_tweet
end
private
def create_tweet
TwitterClient.update("Latest currency rate : 1 USD = #{rate} #{currency.code}")
true
rescu... | true |
40b63efcf6d43740053e0dd2d8155a4d4dea032d | Ruby | rogercampos/vestal_versions | /test/version_test.rb | UTF-8 | 2,218 | 2.6875 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class VersionTest < Test::Unit::TestCase
context 'Versions' do
setup do
@user = User.create(:name => 'Stephen Richert')
@user.update_attribute(:name, 'Steve Jobs')
@user.update_attribute(:last_name, 'Richert')
@fir... | true |
e145d337a9f867cbd1677782b88c9f5c5c51fe19 | Ruby | simplay/rubofrev | /src/game.rb | UTF-8 | 3,148 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'observable'
require 'score'
require 'ticker'
require 'music_player'
require 'pacer'
require 'game_settings'
require 'event'
class Game
include Observable
attr_accessor :map
attr_reader :ticker_thread
def initialize
@turns_allowed = 10_000_000 # TODO: define a more meaningful ending/condition.
... | true |
9672af6c9c61dbf2204ef1a188ccee5ff19ff7b2 | Ruby | thodges314/pragmatic_ruby | /fibonacci.rb | UTF-8 | 788 | 4.0625 | 4 | [] | no_license | def fib_up_to(max)
i1, i2 = 1,1
while i1 <= max
yield i1
i1, i2 = i2, i1+i2
end
end
fib_up_to(1000000000) {|f| print f, " "}
###
puts ""
print ["H", "A", "L"].collect{|x| x.succ}
puts""
puts [1,3,5,7].inject(20) {|sum, element| sum + element}
###
def call_block
puts "Start of method"
yield
yield
puts ... | true |
75338bb68d5508c85097c66c811b7b253009ba59 | Ruby | shinpei01/noguchi_Test | /main.rb | UTF-8 | 489 | 3.546875 | 4 | [] | no_license | class Nabeatsu
def initialize(maxlength,divider)
@maxlength = maxlength
@divider = divider
end
def nabeatsu_countup
i = 1
maxlength = @maxlength
divider = @divider
for i in 1..maxlength do
if i % divider == 0 || i.to_s.include?(divider.to_s)
puts "stupit"
else
... | true |
775301e8aab7844eda08bec0728e9f52e78f06f5 | Ruby | Austin-Salameh/Server-Side-Scripting-Ruby | /SupermanQuiz_ExerciseE.rb | UTF-8 | 7,910 | 3.96875 | 4 | [] | no_license | #--------------------------------------------------------------------------
# Script Name: SupermanQuiz_ExerciseE.rb
# Author: Austin Salameh
# Date: 07/04/2020
# Assignment #4
# Description: This Ruby script demonstrates how to work with loops when
# collecting user input through the cr... | true |
828cd11c5b7d0aa65db0cdd786de4a22e14a722b | Ruby | Itsindigo/takeaway_app | /lib/menu.rb | UTF-8 | 396 | 3.046875 | 3 | [] | no_license | class Menu
attr_reader :meal_choice, :choice_cost
MENU = {
margherita_pizza: 3.50,
pepperoni_pizza: 3.80,
hawaiian_pizza: 3.80,
fries: 2.00,
cheesy_fries: 2.50,
chicken_kebab: 4.00
}.freeze
def self.print_menu
MENU.map do |meal, price|
"%s £%.2f" % [meal.to_s.capitalize, pri... | true |
47d40577d3d36a8ed1bec0703b97f3ddca3b5171 | Ruby | rubiojr/scripts | /mabusers | UTF-8 | 754 | 2.796875 | 3 | [] | no_license | #!/usr/bin/env ruby
RED = "\e[31;1m"
YELLOW = "\e[33;1m"
RESET = "\e[0m"
class String
def red
RED + self + RESET
end
def yellow
YELLOW + self + RESET
end
end
map = {}
if RUBY_PLATFORM =~ /darwin/
cmd = 'ps aux -m'
else
cmd = "ps aux k-rss"
end
`#{cmd}`.each_line do |l|
tokens = l.split
rss, pname = tok... | true |
f9a50891654dc69578bfdd627369c9520c23e121 | Ruby | alexcfawcett/CodeKatas | /BankOCR/number.rb | UTF-8 | 2,096 | 3.40625 | 3 | [] | no_license | class Number
attr_accessor :pattern
def integer_value
@intValue == nil ? -1 : @intValue
end
def set_line1 (line1)
@line1 = line1
try_set_integer
end
def set_line2 (line2)
@line2 = line2
try_set_integer
end
def set_line3 (line3)
@line3 = line3
try_set_integer
end
def try_... | true |
ccb48dec73af9979c38d6e33a35a25c08f1bbc13 | Ruby | Departamento-de-sistemas-Uninorte/class_august_21 | /hola2.rb | UTF-8 | 69 | 2.640625 | 3 | [] | no_license | a, b = 1, 2
c = a * b
puts "results "+ c.to_s
puts "results "+ c.to_s | true |
4e4b1566fa7b0c4e43241bbfe70fa7efa125d9c6 | Ruby | ameir/metaconf | /multiconf.rb | UTF-8 | 2,725 | 2.59375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'yaml'
require 'aws-sdk'
require 'pp'
require 'json'
require 'solve'
require 'erb'
def execute(resource_name, hash, dependencies)
puts "Creating #{resource_name}..."
unless dependencies.empty?
# massage for use in ERB template
erb_template = hash.to_json.gsub(/(\$\{)(\w+.\w+)... | true |
2ff56706b05660bc6789272117a463e08e42f003 | Ruby | RobinSoubry/phase-0 | /week-4/good-guess/my_solution.rb | UTF-8 | 173 | 3.125 | 3 | [
"MIT"
] | permissive |
# Good Guess
# I worked on this challenge [with: Sibel Ergener].
# Your Solution Below
def good_guess? (number)
number.to_i
if number == 42
p true
else
p false
end
end | true |
322079d95bf7141d90c58f1faf2a2bc5fcb16d4e | Ruby | Jmiller1294/collections_practice-online-web-pt-100719 | /collections_practice.rb | UTF-8 | 777 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
new_array = []
array.sort
end
def sort_array_desc(array)
array.sort do |a, b|
b <=> a
end
end
def sort_array_char_count(array)
array.sort do |a,b|
a.length <=> b.length
end
end
def swap_elements(array)
array[1], array[2] = array[2],array[1]
array
end
def reverse_array(array)
... | true |
297f05035d2b0b3c3a0083490c5e18e7ac0b00de | Ruby | annafirtree/odin-connect-four | /lib/two_player_game.rb | UTF-8 | 1,205 | 3.609375 | 4 | [] | no_license | # frozen_string_literal: true
require './lib/connect_four'
# class handles switching between players
class TwoPlayerGame
PLAYER_1 = 0
PLAYER_2 = 1
def initialize(game = ConnectFour.new, player_1 = PLAYER_1, player_2 = PLAYER_2, current_player = PLAYER_1)
@game = game
@player_one = player_1
@player_... | true |
1efbb17c11c92818967ab1f48841cf021aa7991f | Ruby | KathleenScriver/battleshift | /app/models/shooter.rb | UTF-8 | 253 | 2.9375 | 3 | [] | no_license | class Shooter
attr_reader :target, :board
def initialize(board:, target:)
@board = board
@target = target
@message = ""
end
def fire!
space.attack!
end
def space
@space ||= board.locate_space(target)
end
end
| true |
8f9bbc9d7c5949130cd450b4b12a0c033b55a5d3 | Ruby | fatosmorina/Algorithms-and-Data-Structures-in-Ruby | /hackerRank/algorithms/warmup/TimeConversion.rb | UTF-8 | 340 | 3.21875 | 3 | [] | no_license | =begin
see problem here- https://www.hackerrank.com/challenges/time-conversion
=end
#!/bin/ruby
time = gets.strip
if time[8,2]=="AM"
if time[0,2]=="12"
time[0,2]="00"
end
time[8,2]=""
else
unless time[0,2]=="12"
t=time[0,2].to_i
time[0,2]=(t+12).to_s
end
time[8,2... | true |
34984f933b964597709ef7ca00ac406fbd094fdf | Ruby | winifredf/array-CRUD-lab-onl01-seng-ft-030220 | /lib/array_crud.rb | UTF-8 | 1,173 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
# create_an_empty_array = []
create_array = []
end
def create_an_array
# my_family = ["Jasmine", "Winifred", "Mackenzie", "Kaleb"]
great_qualities = ["love", "hope", "peace", "patience"]
end
def add_element_to_end_of_array(array, element)
# array = ["wow", "I", "am", "really"... | true |
d0d275059ebbd836aed37514f1a06f39a439fb12 | Ruby | emilyyz92/anagram-detector-v-000 | /lib/anagram.rb | UTF-8 | 240 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Your code goes here!
class Anagram
attr_reader :word
def initialize(new_word)
@word = new_word
end
def match(array)
array.select do |word_comp|
self.word.split("").sort == word_comp.split("").sort
end
end
end
| true |
7e90e7a49f656fa9cca0ca3fc3be1dbcfae6c415 | Ruby | adkinsm/week1homework | /spec/03_string_spec.rb | UTF-8 | 1,873 | 3.1875 | 3 | [] | no_license |
describe "Strings" do
context "created with double quotes" do
it "are valid" do
"Ruby Course".should eq 'Ruby Course'
end
it "are of class String" do
"Ruby Course".class.should eq String
end
it "can contain bare single-quote (') characters" do
"Ruby Course\'s".should... | true |
e67dd89a82031c8b6b79740df759afe0592ab257 | Ruby | rtanglao/barcode | /download720.rb | UTF-8 | 1,656 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'json'
require 'pp'
require 'curb'
# requires serialized flickr json file to be $stdin or specified on the command line and then
# downloads the flickr "l" with height > 720
$file_number = 1
def fetch_1_at_a_time(urls)
easy = Curl::Easy.new
easy.follow_location = true
urls.each do|... | true |
3d06065814d73014361d9ccc13a8bf1d4058c0aa | Ruby | dbesserman/LS_exercises | /small_problems/easy_7/6.rb | UTF-8 | 518 | 3.78125 | 4 | [] | no_license | require 'pry'
def staggered_case(str)
transform_to_upcase = true
chars = str.chars.map do |char|
new_char = nil
if char =~ /[a-zA-Z]/
new_char = transform_to_upcase ? char.upcase : char.downcase
transform_to_upcase = !transform_to_upcase
end
new_char || char
end
chars.join
end
... | true |
5eeda9cfacfd622036ba8c2ad4df6d958711e958 | Ruby | schucode/StackQueueSort | /spec/selectSort_spec.rb | UTF-8 | 232 | 2.765625 | 3 | [] | no_license | require 'rspec'
require './selectSort.rb'
describe 'select_sort' do
it "returns a sorted array" do
a = [8, 6, 5, 4, 3, 2, 1]
solution = a.sort()
result = select_sort(a)
expect(result).to eq(result)
end
end | true |
87de9e9946ae6424f561aadd5b8801a48531e4f7 | Ruby | wonder-princess/LearningWebApp | /try_ruby/game/character.rb | UTF-8 | 264 | 2.96875 | 3 | [] | no_license | require './attack_methods'
class Character
attr_accessor :hp, :mp, :power
def initialize(hp, mp, power)
@hp = hp
@mp = mp
@power = power
end
def name
''
end
include AttackMethods
end | true |
8dd328e01eda1be983d3825f7f08b473d4e1b1f7 | Ruby | truxxu/danger_api | /db/seeds.rb | UTF-8 | 946 | 2.734375 | 3 | [] | no_license | require 'faker'
Topic.destroy_all
Discussion.destroy_all
Post.destroy_all
puts 'Creating Topics...'
topicsList = ['Politics', 'News', 'Buy&Sell', 'Humor', 'Confessions']
topicsList.each do |item|
topicInstance = Topic.new(
title: item,
description: "Description of Topic #{item}"
)
topicInstance.save!
... | true |
5ab708a345ec8eb791b576dced9b2f82a1ec4abd | Ruby | bagumondigi/farmbot-raspberry-pi-controller | /lib/command_objects/report_bot_status.rb | UTF-8 | 1,089 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'mutations'
module FBPi
# This class reads bot status information that has been cached by the Pi. This
# should not be confused with FetchBotStatus, which actively requests status
# updates from the bot. This command will return a Hash that has all relevant
# information known about the bot
class Rep... | true |
38ea0f3e5f8ff70c10653d03508f7156410b9716 | Ruby | yancya/relationize | /lib/relationize/bq_relationizer.rb | UTF-8 | 1,505 | 2.6875 | 3 | [
"MIT"
] | permissive | require_relative './relationizer'
require 'date'
require 'bigdecimal'
module Relationize
class BqRelationizer < Relationizer
BQ_TS_FMT = "%Y-%m-%d %H:%M:%S %:z"
DEFAULT_TYPES = {
Integer => :integer,
Fixnum => :integer,
Bignum => :integer,
BigDecimal => :integer,
... | true |
c4224cbfc08a3780970727cf630f6954e1a2135a | Ruby | JunichiIto/ruby-3-0-sandbox | /test/integer_zero_example.rb | UTF-8 | 60 | 2.796875 | 3 | [] | no_license | class Numeric
def zero?
false
end
end
puts 0.zero?
| true |
877eb1f85bca1804f745e395d54ef273af9c57bd | Ruby | ah-james/phase-1-project-flatiron | /lib/api.rb | UTF-8 | 612 | 3.265625 | 3 | [] | no_license | # set up like a class
# responsible for talking to API
class API
attr_accessor :teams_array
def initialize
uri = URI("https://www.balldontlie.io/api/v1/teams") #prepares URL to work with gems
formatted_response = JSON.parse(Net::HTTP.get(uri)) #Net::HTTP allows ruby to get informa... | true |
dd52214f6deb1b0ca5045a279de3e6d32729c8cb | Ruby | prandy87/THPRubyBasics1 | /yourname.rb | UTF-8 | 114 | 3.453125 | 3 | [] | no_license | def your_name_input
puts "what is your name ?"
i = gets.chomp
puts "hello, " + i
end
your_name_input | true |
8034a2718844f1e12747546d2f4c8b4ada0802e6 | Ruby | thrigby/elephantitus | /elephant.rb | UTF-8 | 889 | 3.03125 | 3 | [] | no_license | require 'redis'
class Elephant
attr_accessor :id
R = Redis.new
def initialize(id)
@id = id
end
def name
R.get("elephants:#{id}:name")
end
def color
R.get("elephants:#{id}:color")
end
def weight
R.get("elephants:#{id}:weight")
end
def self.next_id
R.incr("elepha... | true |
56b5d85c3eaa65a8f3c32aea5b0b30d246e2c8f4 | Ruby | javiersanzr/RubyLearning | /operadoresAritmeticos.rb | UTF-8 | 1,042 | 4.0625 | 4 | [] | no_license | class HolaMundo
def initialize()
end
def concatenarNumeros()
numUno = 3
numDos = 4
resultado = numUno + numDos
puts "El resultado de #{numUno} + #{numDos} es #{resultado}"
end
def concatenarCadenas()
cadena = "Hola "
cadena << "mundo!"
puts cadena
end
def multiplicarCadenasText... | true |
aa9e3eb5e667cab8fb025dfd5554ba106611ee2e | Ruby | tbscanlon/ruby-kickstart | /session3/challenge/2_hashes.rb | UTF-8 | 633 | 3.9375 | 4 | [
"MIT"
] | permissive | # Given a nonnegative integer, return a hash whose keys are all the odd nonnegative integers up to it
# and each key's value is an array containing all the even non negative integers up to it.
#
# Examples:
# staircase 1 # => {1 => []}
# staircase 2 # => {1 => []}
# staircase 3 # => {1 => [], 3 => [2]}
# staircase 4... | true |
30fac4320fa85ed0b4a8d10189b95f943566a9ee | Ruby | sarahemm/tether | /sim/common.rb | UTF-8 | 3,137 | 2.828125 | 3 | [] | no_license | class UDPSocket
def recv_packet(timeout = nil)
return nil if timeout and !IO.select([self], nil, nil, timeout)
begin
raw_pkt = self.recvfrom_nonblock(32)
pkt = decode_packet(raw_pkt[0])
return TetherFrame.new(pkt, raw_pkt[1][1])
rescue Errno::EAGAIN
return nil
end
end
de... | true |
bac9d9b101bacce6318b6db83b89f9449307599b | Ruby | robbiethebakerman/project_1_spending_tracker | /models/specs/transaction_spec.rb | UTF-8 | 977 | 2.875 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../transaction')
class TestTransaction < MiniTest::Test
def setup
options = {
'id' => 1,
'seller_id' =>2,
'category_id' => 3,
'amount' => 10.50,
'transaction_time' => '2018-11-23 09:35:00',
'description' => ... | true |
accd7d46b83423c6a9186ace7170745686216fb8 | Ruby | keigo-brook/Codeforces | /div2/338/a.rb | UTF-8 | 196 | 3.0625 | 3 | [] | no_license | n, m = gets.split.map(&:to_i)
a = Array.new(m, 0)
n.times do
x = gets.split.map(&:to_i)
x.shift
x.each do |v|
a[v - 1] = 1
end
end
if a.include?(0)
puts 'NO'
else
puts 'YES'
end | true |
d55f81ce3f0b07cee2d446b0f23fdfe79f46bb67 | Ruby | schultyy/monotes | /lib/monotes/sync_list.rb | UTF-8 | 503 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'monotes/models/issue'
module Monotes
class SyncList
def initialize(args)
@list = args.fetch(:list)
@adapter = args.fetch(:adapter)
@repository = args.fetch(:repo)
end
def sync
unsynced = @list.find_all {|issue| issue.unsynced? }
unsynced.map do |issue|
res... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.