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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9c9ed68c7fca810c2b54c135d5148fb61f557312 | Ruby | arjunmdas/sample_code | /polynomials.rb | UTF-8 | 1,238 | 3.703125 | 4 | [] | no_license | class Polynomial
def self.new(inputs)
raise ArgumentError, "Need atleast 2 coefficients" if inputs.length < 2
exponent = inputs.length - 1
str1 = ""
inputs.each do |input|
if (input != 0) && (!input.is_a? String)
str1 += exponent < inputs.length-1 && input... | true |
9448a8dfc5123c582d41afe14741207dd6160167 | Ruby | nixoid/ripple-lib-rpc-ruby | /lib/ripple/models/amount.rb | UTF-8 | 894 | 2.90625 | 3 | [
"ISC"
] | permissive | module Ripple
module Model
class Amount
attr_accessor :currency
attr_accessor :issuer
attr_accessor :value
def initialize(amount_json)
#puts "AMOUNT: " + amount_json.inspect
if amount_json.is_a?(Hash)
# IOU
self.currency = amount_json[:currency]
... | true |
46d94d4b7690c03dfb6772d345ccfe592fedb63b | Ruby | VijayEluri/all | /ruby/euler/017.rb | UTF-8 | 1,093 | 3.890625 | 4 | [] | no_license | SINGLES = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
TEN_TWENTY = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']
TENS = ['zero', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty... | true |
ec92ed1e4dd20c4bcbddb5094532f7036c6fc434 | Ruby | southpawgeek/perlweeklychallenge-club | /challenge-148/abigail/ruby/ch-1.rb | UTF-8 | 200 | 2.671875 | 3 | [] | no_license | #!/usr/bin/ruby
#
# See https://theweeklychallenge.org/blog/perl-weekly-challenge-148
#
#
# Run as: ruby ch-1.rb
#
puts ((0 .. 100) . reject {|n| n . to_s =~ /^0$|[1789]|^2.|[35]$/} . join (" "))
| true |
ec98f6695bc336177b09dd115afc3baa207bace1 | Ruby | lishulongVI/leetcode | /ruby/538.Convert BST to Greater Tree(把二叉搜索树转换为累加树).rb | UTF-8 | 1,622 | 3.734375 | 4 | [
"MIT"
] | permissive | =begin
<p>Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.</p>
<p>
<b>Example:</b>
<pre>
<b>Input:</b> The root of a Binary Search Tree like this:
5
... | true |
8c951ad6f89dca3837da1dd3bc701cb97202983a | Ruby | DRGascon/pass-man | /utils/compare.rb | UTF-8 | 692 | 3.296875 | 3 | [] | no_license | # A comparision operation that always takes the same amount of time
# Taken from: ruby's documentation site
module Utils
############################################################################
# Compare two arrays comparing each byte to make sure we don't leak any
# information about the comparison... | true |
c323291e6d77a4f6d26b0c1d70c3f51701873296 | Ruby | pjg/smhw-event-calendar | /spec/requests/events_spec.rb | UTF-8 | 1,721 | 2.609375 | 3 | [] | no_license | describe 'Events requests' do
let(:body) { JSON.parse response.body }
describe 'GET index' do
context 'when there are no events' do
it 'returns an empty array' do
get events_path
expect(response).to be_successful
expect(body).to be_an Array
expect(body).to be_empty
... | true |
27017ed93c96f145d0703a28057b9ee4968a8970 | Ruby | cha63506/brototype | /spec/spec_helper.rb | UTF-8 | 244 | 2.9375 | 3 | [
"MIT"
] | permissive | require 'brototype'
class Foo
attr_accessor :fired
def initialize
@fired = false
@success = false
@param = nil
@bar = 3
end
def foo
@fired = true
91
end
def throws_error
throw :an_error
end
end | true |
4d0943a113fe6b7d860ed4d6a42929d2d9715081 | Ruby | zouzhile/vw | /bin/vwgen_text_multiclass_test | UTF-8 | 3,423 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
$BASE_DIR = File.absolute_path(File.join(File.dirname(__FILE__), "../"))
require "#{File.join($BASE_DIR, "featuregen/tfidf.rb")}"
require "#{File.join($BASE_DIR, "featuregen/common.rb")}"
def help
puts "vwgen_text_multiclass_test test_input_dir test_output_file training_output_dir [nb_feature_... | true |
85efa5cdd5a2f208f684f5fe06163323c8d9bbba | Ruby | tonyho1992/DropboxTimeMachine | /rubylens/dropboxfiles.rb | UTF-8 | 2,941 | 2.546875 | 3 | [] | no_license | require 'rubygems'
require 'dropbox_sdk'
require 'launchy'
require 'sqlite3'
require 'logger'
require 'fileutils'
require 'date'
# Core Logger init
@log = Logger.new(STDOUT)
@log.level = Logger::DEBUG
APP_KEY = 'd0xovavyvfogdpw'
APP_SECRET = '26tpquugqgz4rlb'
TEMP_DIR = '/Users/tonyho/Dropbox2/Dropbox'
HISTORY_DIR =... | true |
da2e7a7a9f342efc44e10efdf66c63321e6e5213 | Ruby | StevenACZ/ruby-blocks-StevenACZ | /16my_find/my_find_test.rb | UTF-8 | 1,442 | 3.015625 | 3 | [] | no_license | require "minitest/autorun"
require_relative "my_find"
class MyFindTest < Minitest::Test
def test_find_when_element_exists
input = [{ name: "Diego" }, { name: "Wences" }, { name: "Deyvi" }]
name_diego = proc { |e| e[:name] == "Diego" }
name_wences = proc { |e| e[:name] == "Wences" }
name_deyvi = proc ... | true |
91d94ef08b19551d05d01c55595b2518270ddaff | Ruby | jwennerberg/puppet-module-sudo | /lib/facter/sudo_version.rb | UTF-8 | 1,256 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | # Fact: sudo_version
# returns the version of Sudo
#
# Fact: quest_sudo
# boolean based on the presence of quest sudo
#
module Facter::Util::SudoVersion
class << self
def get_sudo_version
response = ''
if File.exists? '/usr/bin/sudo'
path = '/usr/bin/sudo'
@questsudo = false
... | true |
c19060a57c3d82ba5b7e18d99d4b91b90e2f34ea | Ruby | hsmitha26/backend_prework | /day_7/fizzbuzz.rb | UTF-8 | 265 | 4.28125 | 4 | [] | no_license |
print "Pick a number, any number:"
number = gets.chomp.to_i
puts "So you picked #{number}."
1.upto(number){|x|
if x % 3 == 0 && x % 5 == 0
puts "FizzBuzz"
elsif x % 5 == 0
puts "Buzz"
elsif x % 3 == 0
puts "Fizz"
else
puts "#{x}"
end
}
| true |
0ec43d4755fac03a4e7bf68ac030c3dca2c168de | Ruby | Alexis-Trainee/ruby | /ex20.rb | UTF-8 | 2,296 | 3.90625 | 4 | [
"MIT"
] | permissive | input_file = ARGV.first
#define a function print_all, it takes a file object as a parameter
def print_all(f)
#print the content of the file object (a string)
puts f.read
end
#define a function rewind, it takes a file object as a parameter
def rewind(f)
# the seek(procurar) method of classIO, moves the file poin... | true |
5bc6e86ba4502650a6cc8b36458b262fd6390dd7 | Ruby | IsmaelSANE/learn-to-program | /modern-roman-numerals.rb | UTF-8 | 1,913 | 3.8125 | 4 | [] | no_license | def modern_roman_numeral(number)
roman = []
remainer = number
while remainer != 0
case remainer
when 1...4
roman << 'I'
remainer = remainer - 1
when 4
roman << 'IV'
remainer = remainer - 4
when 5...9
roman << 'V'
remainer = remainer - 5
when 9
roman <<... | true |
5b6e0586fdf915a63c908c155f8acde959c4b127 | Ruby | robert-laws/practice-may-2019-procedural-ruby | /data-types/data-types.rb | UTF-8 | 272 | 3.515625 | 4 | [] | no_license | names = ['Bob', 'Kal', 'Ned']
p names.class
:employee_title
p :employee_title.class
employee = { name: 'Bob Cobb', age: 34, current_employee: true }
p employee.class
employee.each do |key, value|
if key == :name
puts "matching with #{value}."
end
end | true |
8762b63d234092b9c7de1d01a0f7593201379902 | Ruby | shaunhk/course_work | /week_1/day_2/conditional_logic/what_animal.rb | UTF-8 | 209 | 3.921875 | 4 | [] | no_license | p "what animal is my favourite?"
input = gets.chomp.downcase
if (input == "dog")
p "This is my favourite animal."
elsif (input == "cat")
p "Cats are okay."
else
p "This isn't my favourite animal."
end
| true |
3cda129867b84375a61907c38d523cd58095adc6 | Ruby | camsys/transam_transit | /app/file_handlers/usage_codes_update_event_loader.rb | UTF-8 | 1,174 | 2.53125 | 3 | [
"MIT"
] | permissive | #------------------------------------------------------------------------------
#
# UsageCodesUpdateEventLoader
#
# Generic class for processing usage update events
#
#------------------------------------------------------------------------------
class UsageCodesUpdateEventLoader < EventLoader
VEHICLE_USAGE_CODES_... | true |
e59c47affc010df2dde0bf04264738d67c84748f | Ruby | indyrb/port | /lib/port/scorable.rb | UTF-8 | 318 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
class Scorable < Sprite
class << self
def score(value = nil)
if value
@score = value
end
@score || superclass.score if superclass.respond_to?(:score)
end
end
def score
self.class.score
end
def add_score
game.score += score
end
end
| true |
445da5f8f9120715ee3b664aa9d060d157eab45b | Ruby | glm729/d3fdg | /ciPrepFunctions.rb | UTF-8 | 2,905 | 2.84375 | 3 | [
"BSD-4-Clause",
"BSD-2-Clause"
] | permissive | #!/usr/bin/env ruby
=begin
Script and functions for getting functions for ChemInfo.
- Given a directory containing JS function definition scripts
- Get all function definitions and names
- Place all in a JS script
=end
# Function definitions
# ------------------------------------------------------------------------... | true |
db999cc3e881ce633650c615b31477953d299a9a | Ruby | padwasabimasala/cluster_tools | /lib/cluster_tools/worker_pool.rb | UTF-8 | 917 | 2.890625 | 3 | [
"MIT"
] | permissive | class ClusterTools::WorkerPool
def initialize(expiration=180)
@expiration = expiration
@tasks = {} # :task => [host1, host2 ...]
@workers = {} # "host" => timestamp
end
def add(host, tasks)
tasks.each do |act|
add_or_update_task(host, act)
@workers[host] = Time.new
end
end
de... | true |
18f60916cc9a68a3b2ea9d4027a901d62ab77522 | Ruby | astoica1986/arithmetic_table | /lib/arithmetic_table/table_generator.rb | UTF-8 | 1,219 | 3.0625 | 3 | [] | no_license | module ArithmeticTable
# main interface class of the app, uses dependency injection classes to
# generate the arithmetic table
class TableGenerator
attr_reader :size, :operator, :options, :sequence_generator,
:matrix_calculator, :table_printer
def initialize(size: nil, operator: nil, **op... | true |
244fad743d2bc0266f25d3c0dbebb419d8cf3f05 | Ruby | DavidAPears/Week3-Day3-Lab-Homework | /models/music_fan.rb | UTF-8 | 947 | 2.9375 | 3 | [] | no_license | require('pg')
# require_relative()
class MusicFan
attr_accessor(:name)
attr_reader(:id)
def initialize(options)
@id = options['id'].to_i if options['id']
@name = options['name']
end
# def save()
# sql = "INSERT INTO customers
# (
# name
# )
# VALUES
# (
# $1
# )
#... | true |
676eb419eaae4e403badff02f710d43bb328f101 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grade-school/653ec64693b644b6a356ad3522caacda.rb | UTF-8 | 325 | 3.375 | 3 | [] | no_license | class School
attr_reader :db
def initialize
@db = Hash.new([])
end
def add(student_name, grade_level)
db[grade_level] += [student_name]
end
def grade(level)
db.fetch(level, [])
end
def sort
sort_students
end
def sort_students
db.each { |grade, students| students.sort }
end... | true |
66882759596b19ce88921f92e4be9ea429badef6 | Ruby | joeyh92989/garage_2102 | /lib/car.rb | UTF-8 | 549 | 3.34375 | 3 | [] | no_license | class Car
attr_reader :description,
:year,
:make,
:color,
:model,
:age
def initialize(description:, year:)
@description = description
@year = year
@make = add_make
@color = add_color
@model = add_model
@age = add_age
en... | true |
fd89650288489ff5c79cf27f28ecee362efd45db | Ruby | mkrahu/launchschool | /exercises/small_problems/vers1/easy_3/palindromic_strings_p2.rb | UTF-8 | 510 | 3.953125 | 4 | [] | no_license | # palindromic_strings_p2.rb
# Palindromic String (Part 2) exercise
# Small Problems exercises from LaunchSchool
def palindrome?(arg)
arg == arg.reverse
end
def real_palindrome?(arg)
string = arg.gsub(/[^a-zA-Z\d]/,'').downcase
palindrome?(string)
end
puts real_palindrome?('madam') == true
puts real_palindrome?... | true |
655aa8e19c8548f109e228e6ce33c1bbc87cd94f | Ruby | Alex-Tideman/fibber | /fibber.rb | UTF-8 | 384 | 3.9375 | 4 | [] | no_license | class Fibber
quantity = 15
def self.fibbonaci(num)
return num if num <= 1
fibbonaci(num - 1 ) + fibbonaci(num - 2)
end
quantity.times do |number|
if (number + 1) % 5 == 0
puts fibbonaci(number).to_s.rjust(fibbonaci(quantity).to_s.length + 1,' ')
else
print fibbonaci(number).to_s.r... | true |
fba5619ff717998ff9a81910550223aa529ff413 | Ruby | jtlai0921/PG20249_example | /PG20249_sample/Ruby268-SampleProgram-UTF8/Ch5/sample154-01.rb | UTF-8 | 166 | 3.015625 | 3 | [] | no_license | File.open("foo.txt", "w"){|file| # 建立新檔案
file.puts "第一行"
}
File.open("foo.txt", "a"){|file| # 在檔案結尾加入一行
file.puts "第二行"
}
| true |
a941c82649728055dca480a0a2b480566c1980ab | Ruby | edmundho/algorithm_projects | /heaps_and_heapsort_project/lib/heap_sort.rb | UTF-8 | 534 | 3.46875 | 3 | [] | no_license | require_relative "heap"
class Array
def heap_sort!
i = 1
while i < length
BinaryMinHeap.heapify_up(self, i)
i += 1
end
# heap = BinaryMinHeap.new
# length.times { heap.push(self.shift) }
# # p heap
# j = heap.store.length
# while j > 0
# self.push(heap.extract)
... | true |
46b45cdb5b1255043867b6e58588f1cc570a074a | Ruby | highdrac/chatbot | /lib/message_formatter.rb | UTF-8 | 611 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | require 'erb'
require File.expand_path(File.dirname(__FILE__)) + "/emoji.rb"
class MessageFormatter
def initialize(platform:)
@platform = platform
end
def get_response(response_data:, response_type:)
begin
data = response_data.data
template = response_data.templates[response_type]
if ... | true |
9b54b21fe952fc5553c211a17c85ba77cbd0523d | Ruby | npwalker/control-repo-vagrant | /lib/puppet_debugging_kit/filter/debug_kit.rb | UTF-8 | 5,396 | 2.609375 | 3 | [] | no_license | require_relative '../logging'
class PuppetDebuggingKit::Filter::DebugKit
# Quick and dirty representation of a version number.
Version = Struct.new(:major, :minor, :patch) do
def to_s
[self.major, self.minor, self.patch].join('.')
end
def series
[self.major, self.minor].join('.')
end
... | true |
ce42cea79089d23b06b6c9bfc5a64ef8999ff407 | Ruby | elreyatee/Tealeaf-Precourse | /exercises2.rb | UTF-8 | 173 | 4.3125 | 4 | [] | no_license | # Exercise 2
# Same as above, but only print out values greater than 5.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each do |number|
if number > 5
puts number
else
next
end
end | true |
49fd81c14c12be07863323a673f5c55145dbba2d | Ruby | slindquist3-zz/deli-counter-001-prework-web | /deli_counter.rb | UTF-8 | 579 | 3.921875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def line(katz_deli)
list = "The line is currently"
if katz_deli.empty? == true
list << " empty."
else
list << ":"
katz_deli.each_with_index do |name, index|
list << " #{index + 1}. #{name}"
end
end
puts list
end
def take_a_number(katz_deli, name)
katz_deli << name
puts "Welcome, #{n... | true |
16fd4f7a1c5e9f8106a0979c2c33d52e1efe817a | Ruby | aamarill/Coding-Exercises | /ruby/linked-lists/remove_duplicates.rb | UTF-8 | 1,021 | 4.0625 | 4 | [] | no_license | require_relative 'linked_list'
# Goes through the list once storing data encountered in a hash table.
# If data is repeated, then that node is replaced with the following node.
# This algorithm is O(n), specially since we assume linked list is not sorted.
def remove_duplicates(linked_list)
if !linked_list.is_a?(Lin... | true |
786588f1b5eb0ff158c3521112bfb97c09533f1e | Ruby | tylermercier/talentlms | /lib/talentlms/client.rb | UTF-8 | 997 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'http'
require 'json'
require 'base64'
module TalentLMS
class Client
def initialize(config = {})
raise ArgumentError.new('Missing api_key') unless config.has_key?(:api_key)
@auth_header = auth_header(config[:api_key])
raise ArgumentError.new('Missing sub_domain') unless config.has_key?... | true |
7a86233b5b4ab13dc1201dee72c3d98c172a4b77 | Ruby | martinsvalin/rails4-rivers | /lib/rivers/channel_parser.rb | UTF-8 | 676 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'open-uri'
require 'nokogiri'
module Rivers
class ChannelParser
@@instance = ChannelParser.new
def parse(url)
xml = Nokogiri::XML(open(url))
xml.xpath('//items/item').map { |node| _build_item(node) }
end
private
def _build_item(node)
keys = [:id, :type_of_media, :ur... | true |
cc8376de32cb0cb396a74752e48bc6cc07b3905d | Ruby | tcollier/roshambo | /lib/roshambo/competitor/cycler.rb | UTF-8 | 431 | 2.6875 | 3 | [
"MIT"
] | permissive | module Roshambo
module Competitor
class Cycler < Player
def reset!(seed)
super
rng = Random.new(seed)
@index = rng.rand(3)
@forward = rng.rand > 0.5
end
def throw
track_and_throw next_throw
end
private
def next_throw
@index += ... | true |
6e5367e8b53ec409860e374f9939c191fdc56344 | Ruby | lockstep/tressle_compare | /app/dashboards/product_dashboard.rb | UTF-8 | 2,873 | 2.5625 | 3 | [] | no_license | require "administrate/base_dashboard"
class ProductDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages through... | true |
f5634d5f13f788c920d91c760c8e22b2b09a8cc9 | Ruby | uidzip/rt-client | /rtxmlsrv.rb | UTF-8 | 8,440 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/ruby
## XML RPC service to provide a cross-platform API for
## RT ticket creation/maintenance. Essentially just a wrapper
## around the rt/client library.
require "rubygems" # so we can load gems
require "rt_client/rt_client" # rt-client REST library
require "xmlrpc/server" # that's wh... | true |
ed0e71f35d3506d8b1ca4bdbedabaf6d623d2bef | Ruby | savyounts/ttt-with-ai-project-v-000 | /bin/tictactoe | UTF-8 | 269 | 2.984375 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative '../config/environment'
game = Game.new
game.start
answer = ""
until answer = "no" || answer == "yes"
puts "Would you like to play again? Yes or No?"
answer = gets.strip
if answer == "yes"
game.start
else
end
end
| true |
9290c7e9cb067284567503d968096927ee429db0 | Ruby | remote-exec/ruby-hooks | /test/ruby-hooks/extensible_test.rb | UTF-8 | 1,259 | 2.75 | 3 | [
"MIT"
] | permissive | =begin
Copyright 2014 Michal Papis <mpapis@gmail.com>
See the file LICENSE for copying permission.
=end
require "test_helper"
require "ruby-hooks/extensible"
class ExtensibleTestClass
include RubyHooks::Extensible
attr_reader :calls
def initialize
@calls = []
end
def count(name)
@calls << name
en... | true |
0497a8fbece4875ff3e9da1538927621087defe5 | Ruby | victorclee/wknd_4 | /algo/missing_letter.rb | UTF-8 | 1,050 | 4.5 | 4 | [] | no_license | # Return the missing letter from a given range of letters passed into the method
# as a string. If there is no missing letter, the method should return nil.
# bonus: returns a string of all missing letters as a string. ex: find_missing_letter("ace") would return "bd", write your own test.
def find_missing_letter(range... | true |
acc6d93aadb22d1dd7ae8dd5a86bde6806b76d4c | Ruby | Kylelkh/bookshare | /lib/core_ext/string_ext.rb | UTF-8 | 874 | 2.8125 | 3 | [] | no_license | # frozen_string_literal: true
class String
def try_to_datetime
str = strip
case str[4]
when '-'
data = str.match(/(\d+)\-(\d+)\-*(\d*)/)
raise ArgumentError unless data
DateTime.new(data[1].to_i, data[2].to_i,
data[3].to_i == 0 ? 1 : data[3].to_i)
when '.'
... | true |
43ad78aa9e74ccb3b64d4bb1abbe4e760a35231a | Ruby | khacnhat/differ | /src/line_splitter.rb | UTF-8 | 589 | 3.375 | 3 | [] | permissive |
module LineSplitter # mix-in
module_function
def line_split(source)
if source.nil?
[]
elsif source == ''
['']
else
lines = source.split(/\n/, -1)
lines.pop if lines.last == ''
lines
end
end
end
# - - - - - - - - - - - - - - - - -
# Note that
# source = "a\nb"
# ... | true |
8cc5b1812455742e90fd2e2b2eb45e915c9c9672 | Ruby | karthickpdy/CP | /a20j/pfast.rb | UTF-8 | 752 | 3.421875 | 3 | [] | no_license | def ones(a)
c = 0
while a > 0
c += a % 2
a /= 2
end
c
end
n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
arr << gets.chomp
end
enemy = []
m.times do
a,b = gets.chomp.split(" ")
val = 0
val |= 1 << arr.index(a)
val |= 1 << arr.index(b)
enemy << val
end
# puts "here #{arr}"
best = 0
(0..(2**n)... | true |
a78aa392d78d215450b4f4f2b5045853a467fe97 | Ruby | egotsev/ruby-retrospective-2 | /solutions/03.rb | UTF-8 | 4,493 | 3.78125 | 4 | [] | no_license | class Expr
def self.build(expression)
case expression[0]
when :number then Number.new expression[1]
when :variable then Variable.new expression[1]
when :+ then Addition.new build(expression[1]), build(expression[2])
when :* then Multiplication.new build(... | true |
f21465f056dbe7c11a3de6f3a319e38beae484f4 | Ruby | Disco-Chef/inheritance_and_self_demo | /restaurant_test.rb | UTF-8 | 378 | 3.1875 | 3 | [] | no_license | require_relative 'restaurant.rb'
puts bonbon = Restaurant.new("Bonbon", "Brussels", 20, "French")
puts "#{bonbon.name} is in #{bonbon.city}"
puts "It can host #{bonbon.capacity} people"
bonbon.capacity = 30
puts "After renovations, it can host #{bonbon.capacity} people"
puts "The restaurant is #{bonbon.open? ? "o... | true |
1c2f7442ba4ba30c40c9bb5c681272f09ed01d99 | Ruby | mkrahu/launchschool | /exercises/ruby_basics/vers1/hashes/adding_the_year.rb | UTF-8 | 172 | 3 | 3 | [] | no_license | # adding_the_year.rb
# Adding the Year exercise
# Ruby Basics exercises from LaunchSchool
car = { type: 'sedan', color: 'blue', mileage: 80_000 }
car[:year] = 2003
p car | true |
860be5b80b88d4c40014e6b436f593d48f4dd7be | Ruby | kairemor/learn-ruby | /string_function.rb | UTF-8 | 628 | 3.5 | 4 | [] | no_license | chaine = "bonjour ou bondoir bienvenue dans votre cours de ruby dans les functions sur les chaines de caracteres"
print ("la chaine est : #{chaine} \n")
puts("le longueur de la chaine est : "+ chaine.length().to_s() )
puts("le chaine en majuscule est : #{chaine.upcase()}")
puts("la chaine toute en miniscule est : #{cha... | true |
263dca7a60a58afc85c64c1f60fbd2b26a308ca5 | Ruby | emtreg/minesweeper | /MineCounter.rb | UTF-8 | 608 | 3.59375 | 4 | [] | no_license | require 'colorize'
require_relative 'game'
class MineCounter
attr_accessor :num_mines
#initializes the number of mines
def initialize(num_mines)
@num_mines = num_mines
end
#displays the mine count
def display
puts "\n"
puts " MINES LEFT: ".green + num_mines.to_... | true |
d2bac1c522cc47f94bb38aa3e4b9078f584d9713 | Ruby | stevetwitte/trapped-in-a-cave | /trapped_in_cave_app.rb | UTF-8 | 1,173 | 3.859375 | 4 | [] | no_license | # Trapped in a cave
# This is a text adventure REPL game
# The game starts with you waking up in a cave
# You don't remember how you got there
# You don't know how to get out
# There is a spider guarding the entrance
require "./trapped_in_cave_mods"
require "./trapped_in_cave_rooms"
include TrappedRooms
include Trappe... | true |
d2c9a82f7c402b33180147a7ec6e1f8b702ac6a2 | Ruby | jrkanu/LaunchSchool | /excercises/rb101-rb109/easy-1/count_occurences.rb | UTF-8 | 988 | 4.5625 | 5 | [] | no_license | # Write a method that counts the number of occurrences of each element in a given array.
vehicles = [
'car', 'car', 'truck', 'car', 'SUV', 'truck',
'motorcycle', 'motorcycle', 'car', 'truck'
]
# plan:
# create a hash whose keys are the unique values of the array, and whose values are initiated to 0
# interate ove... | true |
ce190098af71f41412fb11f4968c44bc1e192f18 | Ruby | guyviner/codecorelife | /day5/day5 TA notes/oop.rb | UTF-8 | 190 | 2.640625 | 3 | [] | no_license | # morning cohort 15!
# design, idea, concept
# class - class names are Capitalized, and CamelCased.
# ThisIsAnExampleOfCamelCase
class Cookie
end
# baking, building, constructing
# object
| true |
9c7a713153c9cbfaaa6abe8fddd28462859644d7 | Ruby | LuizaMagalhaes/bank-api | /spec/models/transference_spec.rb | UTF-8 | 1,208 | 2.59375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Transference, type: :model do
before(:each) do
@account1 = Account.create(name: 'Harry Potter', balance: 90.0)
@account2 = Account.create(name: 'Hermione Granger', balance: 180.0)
@transference = Transference.new(amount: 10.0, account_source_id: @account1.id, account... | true |
53f962e06961552c8b202d84052deef7900959e3 | Ruby | HeartyRhombus/parrot-ruby-onl01-seng-ft-090820 | /parrot.rb | UTF-8 | 67 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def parrot (sound="Squawk!")
puts "#{sound}";
return sound
end
| true |
a00450d3524f297a1f9aef8a59005afabbfb6029 | Ruby | MatzFan/old_jps | /test/lib/scrapers/test_app_details_scraper.rb | UTF-8 | 1,670 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../../test_helper'
require_relative '../../../lib/scrapers/app_details_scraper'
class AppDetailsScraperTest < Minitest::Test
def self.details_hash
{ app_ref: 'RW/2014/0548', app_category: 'RW', app_status: 'Upheld',
app_officer: 'Richard Greig', app_applican... | true |
70b759d553c2f52aad87aa07ce67e0ed066f5942 | Ruby | italopolazzi/college-projects | /Ruby/string_colorize.rb | UTF-8 | 686 | 3.453125 | 3 | [] | no_license | =begin
---- 0 - normal
---- 1 - negrito
---- 3 - itálico
---- 4 - sublinhado
---- 5 - pisca lento
---- 6 - pisca
---- 8 - oculto
---- 9 - sobreposto
30..37 - cores
40..47 - fundos
=end
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def random
colorize rand 30..... | true |
833814fd8425e19eec86e0f9da21bacd683ad99f | Ruby | ryz310/unagi | /spec/unagi_spec.rb | UTF-8 | 2,111 | 3.046875 | 3 | [] | no_license | require './unagi.rb'
describe Unagi do
describe '#initialize' do
it '初期化すると 引数で指定したサイズの配列が 0 で初期化された状態で作成される' do
unagi = Unagi.new(3)
expect(unagi.seats).to eq [0, 0, 0]
end
end
describe '#seating' do
let(:unagi) { Unagi.new(5) }
it '引数で渡された人数と座席番号の seats に 1 が代入される' do
unagi.... | true |
9a1e1c58f695ac5d9408b7bed06e49d991baf1d9 | Ruby | gannagoodkevich/interest_mate_social_network | /app/services/post_updating_service.rb | UTF-8 | 698 | 2.859375 | 3 | [] | no_license | class PostUpdatingService
def initialize(post)
@post = post
end
def call(post_params)
@post.update!(title: post_params[:title], content: post_params[:content], status: post_params[:status])
update_category(post_params[:category_id])
update_tag(post_params[:tags])
end
private
def update_ca... | true |
0aac2dbb03880d46806fd4ea34736b4be890e914 | Ruby | MisterZW/school_projects | /cs_1632/Deliverable 2/tests/location_test.rb | UTF-8 | 3,153 | 3.421875 | 3 | [] | no_license | require 'minitest/autorun'
require_relative '../location.rb'
class LocationTest < Minitest::Test
def setup
@random = Random.new
@test_neighbor_list = [
Location.new('TOWN 1', 0, 4, @random),
Location.new('TOWN 2', 1, 2, @random),
Location.new('TOWN 3', 2, 2, @random),
Location.new('T... | true |
61b34de67310197332d440f2d891f6d653afb953 | Ruby | AmalReyad/BloodDonation | /app/models/request.rb | UTF-8 | 2,529 | 2.734375 | 3 | [] | no_license | require 'Obfuscate'
class Request < ActiveRecord::Base
include Obfuscate
validates_presence_of :contact_name, :message=> "Must enter your name!"
validates_presence_of :contact_phone, :message=> "Must enter your Mobile number!"
validates_length_of :contact_phone, minimum: 11, maximum: 11, :message=> "Mo... | true |
2f75ff479a002225e012bf00443ae7cfbf6e851c | Ruby | codecrutch/nexus-top-1000 | /spec/character_list_spec.rb | UTF-8 | 2,707 | 3.015625 | 3 | [] | no_license | require 'spec_helper'
describe CharacterList do
before :all do
# Memoize both lists in order to stop new GET requests being
# sent via Nokogiri.
@one_thousand_characters ||= CharacterList.new
@two_fifty_characters ||= CharacterList.new(path: :MAGE)
end
context '#all_chars' do
context 'with 1... | true |
aaeccf62af879bfad1682a6cabaf1e1bd5c54fd9 | Ruby | bexluong/Ironhack-Bootcamp | /Week2/Day 1/lexiconomitron_spec.rb | UTF-8 | 541 | 3.25 | 3 | [] | no_license | require 'rspec'
require './lexiconomitron'
RSpec.describe 'lexi' do
before :each do
@lexi = Lexiconomitron.new
end
# describe '#eat_t' do
# it 'removes every letter t from the input' do
# expect(@lexi.eat_t('great scott!')).to eq('grea sco!')
# end
# end
describe 'shazam' do
it 'takes... | true |
901fe5f5dc577b9c7d3178f4a9640ac2c7e199d8 | Ruby | rclacerna/rehub | /app/controllers/file_managers_controller.rb | UTF-8 | 2,575 | 2.671875 | 3 | [] | no_license | class FileManagersController < ApplicationController
def index
# render :file => '/app/views/file_managers/upload.html.erb'
end
def create
@filename_n_wordcount = []
@records = Dir.glob("public/files/*")
if request.post?
# gets file input from the user
uploaded_io_arr = []
uploaded_io_... | true |
f3a614341cb121a4bf6666995a760307fde622c7 | Ruby | Alexcyt/taoshu | /lib/tasks/get_book_info.rake | UTF-8 | 808 | 2.609375 | 3 | [] | no_license | namespace :db do
desc "get book data from txt"
task get_book_data: :environment do
dir_path = "./lib/tasks/book_dir/"
Dir::foreach(dir_path) do |path|
if path != "." && path != ".."
file_path = dir_path + path
tmp_file = File.new(file_path, "r")
str = ""
tmp_file.each_l... | true |
f8ae84c581f871c41ae5911500881143243d08f5 | Ruby | alikayaa/ruby-learn | /io.rb | UTF-8 | 535 | 4.28125 | 4 | [] | no_license | =begin
Example of Ruby's Basics.
#101: get input and show output.
=end
# write single line text without \n
print "Please, enter your first name:"
# get user input from console
first_name = gets.chomp
# write single line text without \n
print "Please, enter your last name:"
# get user input from
last_name ... | true |
789bf3700590ffb4bbea1907295bc98ab7795c58 | Ruby | inbabbini/ttps_ruby_2015 | /Practicas/Practica2/metodos/e6.rb | UTF-8 | 1,634 | 3.71875 | 4 | [] | no_license | #encontrar los problemas con el siguiente codigo
# Tira un dado virtual de 6 caras
def tirar_dado
rand 1..6
end
# Mueve la ficha de un jugador tantos casilleros como indique el dado en un
# tablero virtual de 40 posiciones.
# Si no se recibe la cantidad de casilleros, aprovecho el valor por defecto
# para ese pará... | true |
36a02352d8b508e322755c27f4602ce960be58fb | Ruby | jnjensen/Ruby_Bubble_Sort | /bubble_sort.rb | UTF-8 | 672 | 3.890625 | 4 | [] | no_license | def bubble_sort(array)
sorted = false
sorted_array = array
while sorted == false
changes = 0
0.upto((array.length-2)) do |idx1|
idx2 = idx1 + 1
num_a = sorted_array[idx1]
num_b = sorted_array[idx2]
if num_b < num_a
sorted_array... | true |
1007f73e2e1ccdd88494be1315e47ef0522276d6 | Ruby | ga-wdi-boston/wdi_2_ruby_lab_exceptions | /person.rb | UTF-8 | 634 | 3.890625 | 4 | [] | no_license | class PersonValidError < StandardError
end
class Person
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age = age
end
end
tom = Person.new('tom', 57)
puts "tom's name is " + (tom.valid_name? ? "valid" : "not valid")
puts "tom's age is " + (tom.valid_age? ? "valid" : "not valid")
ed ... | true |
42b630059171fe8e444d3e30f3ca7f0468165f19 | Ruby | seenevz/activerecord-validations-lab-london-web-121018 | /app/models/post.rb | UTF-8 | 617 | 2.71875 | 3 | [] | no_license | class Post < ActiveRecord::Base
validates :title, presence: true
validates :content, length: {minimum: 250}
validates :summary, length: {maximum: 250}
validates :category, inclusion: {in: %w(Fiction Non-fiction)}
validate :clickbait
def clickbait
if self.title
title_array = self... | true |
a8c54c122e4114faf75a1f989972fc1b4811e093 | Ruby | andrewprogers/light-synchronizer | /spec/bridge_spec.rb | UTF-8 | 1,052 | 2.71875 | 3 | [] | no_license | require_relative '../lib/bridge.rb'
describe Bridge do
let(:bridge) { Bridge.new(ENV['HUE_BRIDGE_IP'], ENV['HUE_BRIDGE_USERNAME']) }
describe 'initialization' do
it 'creates a new bridge connection with specified ip address and username' do
expect(bridge.class).to eq(Bridge)
end
end
describe '#... | true |
5c8a8c7dadb0b7215c0c19c904d1e5933ce295c5 | Ruby | yxia521/RB101_Programming_Foundation | /RB101_109_Small_Problems/Easy_5/1.rb | UTF-8 | 390 | 3.875 | 4 | [] | no_license | # returns the ASCII string value of a string
# The ASCII string value is the sum of the ASCII values of every character in the string
def ascii_value(str)
sum = 0
str.each_char { |char| sum += char.ord }
sum
end
# or simply:
# def ascii_value(str)
# str.sum
# end
ascii_value('Four score') == 984
ascii_value... | true |
67409f194258c5a48378d8b175dc8ef4d020dd1b | Ruby | neinteractiveliterature/intercode | /app/liquid_drops/order_entry_drop.rb | UTF-8 | 1,166 | 2.71875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# An entry in an order
class OrderEntryDrop < Liquid::Drop
# @api
attr_reader :order_entry
# @!method id
# @return [Integer] The numeric database id of this order entry
# @!method order
# @return [OrderDrop] The order this entry is part of
# @!method price
# @return ... | true |
f30427fca9f0c1ff152dc7489f7a674d9ca5bed5 | Ruby | oldermcdonald/SEI_Warmups | /day23-starbucks/starbucks-ordering.rb | UTF-8 | 1,384 | 4.3125 | 4 | [] | no_license | # Warmup - Wk6 - Monday
# Starbucks
# Write a program that holds on to coffee orders.
# c1 = Coffee.new('Darryl', 'latte', 'medium', 2)
# Write the .to_s method for this class so when you puts c1 you will have "Darryl's latte, medium, 2 sugars."
# Extension
# Starbucks always gets names wrong, however. Make the name... | true |
463c9bdace728e1feb9707e9ec47442006c5fb5d | Ruby | allforkedou/nextacademyMY | /week4/address_book_db_from_schema.rb | UTF-8 | 4,126 | 2.890625 | 3 | [] | no_license | require 'sqlite3'
$db = SQLite3::Database.new "contacts.db"
module ContactsGroupsDB
def self.setup
contacts_query =
<<-SQL
CREATE TABLE contacts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
address VARCHAR(64) NOT NULL,
... | true |
8fe3485c431ca9ad8794bd118700730b49200557 | Ruby | LiliLaeti/ruby_projet1 | /exo14.rb | UTF-8 | 76 | 2.875 | 3 | [] | no_license | num = 1
52.times do |num|
if num % 2 ==0
puts "jean.dupont.#{num}@email.com"
end
end | true |
5da5bcf494f9c2890e66d617bf8cb22f12737c15 | Ruby | ttuffy/docker_design_pattern | /app/models/iterator/other.rb | UTF-8 | 1,136 | 4.03125 | 4 | [] | no_license | def for_each_element(array)
i = 0
while i < array.length
yield(array[i])
i += 1
end
end
###############################################################################
a = [10, 20, 30]
for_each_element(a) {|element| puts("The element is #{element}")}
####################################################... | true |
0e3653f366c907b9c547a164f3fda5dad60ceb10 | Ruby | thoferon/simplessh-rb | /lib/simplessh/either.rb | UTF-8 | 1,733 | 2.984375 | 3 | [] | no_license | module SimpleSSH
class Either
attr_reader :val
def self.return(val)
Right.new val
end
def initialize(val)
@val = val
end
def self.from_pointer(pointer, &block)
if SimpleSSH::Foreign.is_left(pointer) == 0
value_pointer = SimpleSSH::Foreign.value pointer
valu... | true |
0c169ace498eb6586b203b5b61f185d0caa60b18 | Ruby | xxKeefer/ca_coursework | /challenges/xxkeefer_bank/funds.rb | UTF-8 | 2,638 | 3.53125 | 4 | [] | no_license | module Funds
require_relative "password.rb"
include Password
require_relative "balance.rb"
include Balance
def deposit(user_obj)
if user_obj.password.nil?
#ask for a password to be set if none has been provided yet before proceding
return "Please set your password first with menu option 4."
else
if check... | true |
844298349bf6510e19088ae42e78d4c052c5bf41 | Ruby | jessecalton/WatchNext | /spec/helpers/sessions_helper_spec.rb | UTF-8 | 1,340 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the SessionHelper. For example:
#
# describe SessionHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# en... | true |
b4343a67fe422008565b92807373d64bf56f4fe6 | Ruby | aberant/midi-message | /lib/midi-message/short_message.rb | UTF-8 | 3,080 | 2.875 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
#
module MIDIMessage
# common behavior amongst all Message types
module ShortMessage
attr_reader :name,
:status,
:verbose_name
def initialize_short_message(status_nibble_1, status_nibble_2)
@status = [status_nibble_1, status_nib... | true |
40953eb87a04800444f4175d7a0b32db88eaad99 | Ruby | ReneeVL85/my-ruby-code | /Store/menu.rb | UTF-8 | 438 | 3.453125 | 3 | [] | no_license |
class Menu
def initialize
@menu_options = "What would you like to do?
1) View the Beerstore inventory
2) Order Beer
3) View your Beercart
4) Remove from your Beercart
5) Pay your Beer
6) Nothing"
end
def menu_options
p @menu_options
choice = gets.chomp.to_i
if choice =... | true |
18ea5ae9d2c75bac0ff5f2e8c9dec4ac8fb956bb | Ruby | masayasviel/algorithmAndDataStructure | /from151to200/ABC173/mainC.rb | UTF-8 | 861 | 3.328125 | 3 | [] | no_license | $ans = 0
$H, $W, $K = gets.chomp.split(" ").map(&:to_i)
def count_black_math(color)
res = 0
$H.times do |i|
$W.times do |j|
res += 1 if color[i][j] == "#"
end
end
$ans += 1 if res == $K
end
color = []
$H.times do
color << gets.chomp.split("")
end
[0, 1].repeated_permut... | true |
8944bd5f01bb29aa32a2e163be598d6e44ff3222 | Ruby | CalvinLac/Blackjack-with-sinatra | /lib/deck.rb | UTF-8 | 279 | 3.15625 | 3 | [] | no_license | class Deck
#Forming the deck for all possible cards
def initialize
@possible_cards = [2,3,4,5,6,7,8,9,10,10,10,10,11]
end
#Running the sample method to generate a random object from possible cards
def random
card_dealt = @possible_cards.sample
end
end
| true |
225554659b8d31e19566796ede014c5ab5252c3e | Ruby | nofxx/geonames_local | /lib/geonames_local/models/tokyo.rb | UTF-8 | 2,101 | 2.625 | 3 | [
"MIT"
] | permissive | module Geonames
module Models
module Tokyo
class Nation
attr_accessor :code, :name, :gid, :iso, :capital, :pop, :currency
def self.all
Tokyo.new.all({ :kind => "nation" }).map do |c|
new(c)
end
end
# [0] iso alpha2
# [1] iso alpha3
# [2] iso numeric
# [3] fips ... | true |
bee12ef6bb50feb1b272cc4d28d0bdcf0e78f6f3 | Ruby | johnsmith0707/life_game | /life_game.rb | UTF-8 | 684 | 2.734375 | 3 | [] | no_license | require './cell'
target_cell = Cell.new(Cell::ALIVE_STATUS)
alive_cell = Cell.new(Cell::ALIVE_STATUS)
dead_cell = Cell.new(Cell::DEAD_STATUS)
p '***********************************************'
p "target cell status is #{target_cell.status}"
8.times do
# p 'an alive cell aadjoin to target_cell'
target_cell.adjoin(... | true |
0fcdac5c6d3f6e2e02d23ce24347d16c01c54306 | Ruby | shyamrallapalli/cheripic | /lib/cheripic/vcf.rb | UTF-8 | 3,771 | 2.734375 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
module Cheripic
# Custom error handling for Vcf class
class VcfError < CheripicError; end
require 'bio-samtools'
class Vcf
def self.get_allele_depth(vcf_obj)
# check if the vcf is from samtools (has DP4 and AF1 fields in INFO)
if vcf_obj.info.key?('DP4')
freq = vcf... | true |
a020cf64c400c8f81c80d806c4ac3114ec4575f1 | Ruby | Envinorma/envinorma-web | /app/resources/odf/table.rb | UTF-8 | 2,510 | 2.640625 | 3 | [] | no_license | # frozen_string_literal: true
module Odf
module Table
include Odf::XmlHelpers
def table_from_template(table_template, table_struct_to_insert, cell_placeholder)
output_table = deep_clone(table_template)
ensure_one_cell(output_table)
generate_table(output_table, table_struct_to_insert, cell_... | true |
b8f8ac84e277406a9a079f870b638efca8a86a61 | Ruby | katheroine/languagium | /ruby/strings/string_trimming.rb | UTF-8 | 185 | 2.921875 | 3 | [] | no_license | #!/usr/bin/ruby2.7
sententia = " Sapere aude. "
puts("sententia = <#{sententia}>\n\n")
trimmed_sententia = sententia.strip
puts("trimmed sententia = <#{trimmed_sententia}>\n\n")
| true |
bf983d2450bc96f532221743250225f84a1f5c65 | Ruby | blakedixon/launchschool | /small_problems/leap_years.rb | UTF-8 | 766 | 3.578125 | 4 | [] | no_license | def leap_year?(num)
four_divisibility = num % 4 == 0
hundred_divisibility = num % 100 == 0
four_hundred_divisibility = num % 400 == 0
if num < 1752 && num % 4 == 0
return true
elsif ( four_divisibility && hundred_divisibility && four_hundred_divisibility ) || ( four_divisibility && !hundred_divisibility ... | true |
ebdabda325bc02851932cfa35bfdcf10bcce30c6 | Ruby | jctbog9/Whiteboarding-Challenges | /code.rb | UTF-8 | 859 | 3.75 | 4 | [] | no_license | require 'pry'
require './data/questions'
puts "Welcome to Whiteboarding Practice!\nWhich questions would you like to practice?"
puts "1. Easy\n2. Medium\n3. Hard\n4. All"
print "> "
questions = gets.chomp
level_validator = ["1", "2", "3", "4", "easy", "medium", "hard", "all"]
while !level_validator.include?(questio... | true |
55268b9c618c167cccef05359ae5f4baa8d1cb8e | Ruby | shott2/Final-Project | /lib/trackSite.rb | UTF-8 | 3,159 | 2.796875 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
class TrackHelper
def initialize
scratchExercisePage
end#end initialize
def chooseRandPage
@baseSite = "http://www.jefit.com/exercises/bodypart.php?id=11&exercises=All&All=0&Bands=0&Bench=0&Dumbbell=0&EZBar=0&Kettlebell=0&MachineStrength=0&MachineCardio=0&Barbell=0... | true |
07fff045821f91279274bc35cf2140cf97ff5a1e | Ruby | DakotaLMartinez/oo-cash-register-v-000 | /lib/cash_register.rb | UTF-8 | 957 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :discount, :total, :items, :last_transaction
def initialize(discount=0)
self.total = 0
self.discount = discount
self.items = []
self.last_transaction = {}
end
def add_item(title, price, quantity=1)
self.last_transaction = {title: tit... | true |
00d890eea678fb20384cb121e8a73297baa8d70b | Ruby | Kone7347/EuP-1 | /Ruby/Aufgaben/classes.rb | UTF-8 | 369 | 3.734375 | 4 | [] | no_license | class Movie
def initialize(para_name, para_rank=5)
@name = para_name
@rank = para_rank
end
def list_movie
"Movie heisst: #{@name} und hat einen Rank von: #{@rank}"
end
def thumbs_up(value)
@rank += value
end
end
obj = Movie.new("Superman")
puts obj.list_movie
obj.thumbs_up(2)
puts obj.list_movie
obj... | true |
027b1e9a49724d8f2ac7fc4b516ecb32ba631563 | Ruby | adrianpike/wayfarer | /server/objects.rb | UTF-8 | 1,456 | 2.828125 | 3 | [] | no_license | module Wayfarer
module Objects
class Base
attr_accessor(:x,:y,:heading, :game_id)
def initialize
@x=0;@y=0;@heading=0;@game_id = Wayfarer::World.unique_id
end
def tick
end
def to_s
"#{self.class.to_s} (##{game_id}) - #{x},#{y},#{heading}"
end
def to_json
'{"game_i... | true |
10000836510a63dd4a497bdd53a1c7de481b32ec | Ruby | topbitdu/unidom-category | /app/models/unidom/category/category_rollup.rb | UTF-8 | 1,871 | 2.5625 | 3 | [
"MIT"
] | permissive | ##
# Category Rollup 是分类的层级关系。
class Unidom::Category::CategoryRollup < Unidom::Category::ApplicationRecord
self.table_name = 'unidom_category_rollups'
include Unidom::Common::Concerns::ModelExtension
validates :distance, presence: true, numericality: { integer_only: true, greater_than: 0 }
belongs_to :anc... | true |
894125c8628d62f4104ac91b6fb68841a5991d18 | Ruby | viniciusknabben/ruby | /intro/13_modules/fighter.rb | UTF-8 | 481 | 2.796875 | 3 | [] | no_license | #!/usr/ruby -w
require "logger"
require_relative "mixins"
module Logging
# Provided for your convenience
def logger
Logging.logger
end
def self.logger
@logger ||= Logger.new(STDOUT)
end
end
class Fighter
# Your code goes here
include JeetKuneDoMixin
include Logging
def initialize (name... | true |
5087c1f5009b8005caf3a7c6be93ca68c66df32c | Ruby | dantelove/109_general_programming | /ruby_basics/6_user_input/user_input4.rb | UTF-8 | 349 | 3.84375 | 4 | [] | no_license | # user_input4.rb
def prompt(msg)
puts ">> #{msg}"
end
loop do
prompt "Do you want me to print something? (y/n) "
ans = gets.chomp
if ans.downcase.start_with?('y', 'n')
case ans.downcase
when 'y'
prompt "something"
when 'n'
# do nothing
end
break
else
prompt "Please... | true |
00881a6ec4b7209e933024977b6a8c78be501b3d | Ruby | mlackman/fake | /lib/fake/response.rb | UTF-8 | 466 | 2.765625 | 3 | [
"MIT"
] | permissive |
module Fake
class Response
attr_reader :body
attr_accessor :status
attr_accessor :headers
def initialize(body, status, headers, &block)
raise "Response created with body and block. Only other can be given" if body && block
@body = body
@status = status
@block = block
... | true |
43fdb6863208e3e3f7833f6db01622e6bf5ca810 | Ruby | marcwright/WDI_ATL_1_Instructors | /REPO - DC - Students/w05/d05/JoElla/projectone/api_calls/read_from_twitter.rb | UTF-8 | 1,047 | 2.890625 | 3 | [] | no_license | require 'twitter'
require 'pry'
require 'httparty'
require 'json'
@client = Twitter::REST::Client.new do |config|
config.consumer_key = 'vkSO6FNqJHy0vNwOwoc1F8bkU'
config.consumer_secret = 'GTC0wCHToAySkiaQuVNZDciTd8Lv3leutBpsQp0uipMLc8b46l'
config.access_token = '260052956-aAcvbzbYNdisIBNuTMvED4C6UXxaRUpvXENWpN... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.