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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6fcf5f57d3eb42fdb6b2fe3ba90f4173ba758e0d | Ruby | roblingle/weasel | /lib/evolver.rb | UTF-8 | 4,261 | 3.609375 | 4 | [] | no_license | class Evolver < String
attr_accessor :parent, :generation, :children, :options
def initialize( initial, options = {} )
@options = {
:target => "Methinks it is like a weasel",
:offspring => 100,
:length_penalty => 25,
:spelling_multiplier => 1,
:s... | true |
8654fa6438ebbc9bcb849f83f6628ad644aa9b47 | Ruby | jaywritescode/projecteuler-ruby | /graphs/graph.rb | UTF-8 | 1,720 | 3.515625 | 4 | [
"MIT"
] | permissive | class Graph
attr_reader :vertices
# True iff there is an edge in the graph from x to y.
#
# @param [Vertex] x
# @param [Vertex] y
# @return [Boolean]
def adjacent(x, y)
raise
end
# Get the neighbors of vertex x.
#
# @param [Vertex] x
# @return Set<Vertex>
def neighbors(x)
raise
en... | true |
4ce33e1b116209a6b8c06c519b2b7a2c6ac880bb | Ruby | Slav666/caraoke-weekend2-homework | /weekend2_home_work/specs/room_spec.rb | UTF-8 | 1,531 | 3.40625 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../room.rb')
require_relative('../song.rb')
require_relative('../guest.rb')
class RoomTest < Minitest::Test
def setup
@song1 = Song.new("Guns N' Roses", "November Rain")
@song2 = Song.new("Guns N' Roses", "Paradise City")
@song3 = Son... | true |
92c22986c5a1a0c3d91350b500bbecfe06c8a67d | Ruby | sandratoh/learn-ruby | /ruby-exercises/ex34.rb | UTF-8 | 882 | 4.28125 | 4 | [] | no_license | # Ruby array is zero-indexed - cardinal number
animals = ['bear', 'tiger', 'penguin', 'zebra']
bears = animals[0]
animals = ['bear', 'ruby', 'peacock', 'kangaroo', 'whale', 'platypus']
# The animal at 1.
puts 'The animal at 1 is the 2nd animal and is a: ' + animals[1];
# The third (3rd) animal.
puts 'The third (3rd)... | true |
04fdb93fefb15af2b2d7c720a62efd81cbcc03dc | Ruby | crawsible/advent-2020 | /11/seating_modeler_b.rb | UTF-8 | 2,009 | 3.546875 | 4 | [] | no_license | #!/usr/bin/env ruby
class SeatLayout
attr_reader :height, :width
def initialize(matrix)
@matrix = matrix
@height, @width = @matrix.length, @matrix.first.length
end
def ==(other)
return false unless @height == other.height && @width == other.width
(0...@height).each do |row|
(0...@width... | true |
46fefdd4c5f5aa411e6f9613e466e7582199c5a7 | Ruby | BrianDunlap89/practice | /consecutive_primes.rb | UTF-8 | 205 | 2.75 | 3 | [] | no_license | require 'pry'
File.open('test-lines.rb', 'r') {|file| @text = file.read}
lines = @text.each_line do |line|
array = (1..(line.chomp.to_i)).to_a
permutations = array.permutation.to_a
binding.pry
end | true |
56d3764b4551501bd7e6cb179ebbb9a63ae4f980 | Ruby | aziflaj/ascii-to-svg-generator-for-ruby | /test/test.rb | UTF-8 | 2,288 | 3.0625 | 3 | [
"MIT"
] | permissive | require '../lib/ascii_to_svg'
sets = [
{
test: 'Draw symbols',
characters: [ '-', '/', '|', "\\", '+' ],
times: 512,
chars: 32,
path: '0-many-characters.svg',
params: {}
},
{
test: 'Change default canvas size',
characters: [ '-', '/', '|', "\\... | true |
9994cd20072870bb2c3af044b2612a425bf29d7f | Ruby | ouskah/Jeu_plus-moins_ruby | /jeu_plus-moins.rb | UTF-8 | 756 | 4.03125 | 4 | [] | no_license | # nombre d'essais
essais = 0
# Le programme tire un nombre entre 1 et 100
solution = rand(99) + 1
# valeur de lancement de la variable "nombre" pour un 1er tour de boucle
nombre = -1
# Le programme indique si ce nombre est inférieur, supérieur ou égal au tirage
while solution != nombre
# L'utilisateur saisit u... | true |
68021c24a40b36c8319715d70d2cb6fb12da5bc7 | Ruby | bezelga/tod | /lib/tod/tasks_repository/in_memory.rb | UTF-8 | 342 | 2.640625 | 3 | [
"MIT"
] | permissive | module Tod
module TasksRepository
class InMemory
def initialize
@tasks = {}
@id = 0
end
def persist(task)
@id += 1
task.id = @id
tasks[@id] = task
task
end
def count
tasks.length
end
private
attr_reader :ta... | true |
95d9f329989b6da82f0ad9a3e7160a326f20563f | Ruby | Alpenglow88/oTTo | /features/support/multiple_assertions.rb | UTF-8 | 2,012 | 2.84375 | 3 | [] | no_license | # frozen_string_literal: true
module MultipleAssertion
# A Class which allows RSpec expect blocks to go through the whole block before failing - speeding up debug/fixes
class CustomExceptions < RSpec::Expectations::ExpectationTarget
attr_accessor :error_message
@@error_message = [] # rubocop:disable Style... | true |
ebb78c45b6bfad4b0987f5316f55f53fb9382688 | Ruby | ryanhageman/gallery-calculator | /spec/services/square_inch_calculator_spec.rb | UTF-8 | 576 | 2.96875 | 3 | [] | no_license | # frozen_string_literal: true
require 'spec_helper'
require_relative '../../services/square_inch_calculator'
RSpec.describe 'SquareInchCalculator' do
it 'calculates a price in linear inches' do
length = 3
width = 3
price_per = 3
result = SquareInchCalculator.new(length, width, price_per).call
... | true |
d61c632c342827a6dfbb76886cb2dd60d5500b71 | Ruby | ArjunAranetaCodes/MoreCodes-Ruby | /Easy Problems/problem18.rb | UTF-8 | 249 | 3.546875 | 4 | [] | no_license | #Problem 18: Write a program that outputs the frequency of a
#letter in a string.
word = "program"
letter = "a"
letterCount = 0
word.split("").each do |x|
if letter.include? x
letterCount = letterCount + 1
end
end
print "Total: ", letterCount
| true |
1237f0b61442d4f0883348c291bdddf99413e0b4 | Ruby | nekoTheShadow/atcoder-answers | /ABC197/a.rb | UTF-8 | 33 | 3.203125 | 3 | [] | no_license | s = gets.chomp
puts s[1..] + s[0] | true |
156f54a7fd912b49822d0239e78095476700f672 | Ruby | senenalonso/RUBY | /Person.rb | UTF-8 | 301 | 3.640625 | 4 | [] | no_license | class Person
attr_reader :name, :age
attr_writer :age
def initialize(name,age)
@name = name
@age = age
end
end
person1 = Person.new("Senén", 38)
person2 = Person.new("Senén Jr.", 7)
puts person1.name
puts person1.age
#person1.name="Yo"
person1.age = 55
puts person1.name
puts person1.age
| true |
b18c5840f33f625e2d51f8783dac102a70b17cc6 | Ruby | 905205650/AI-in-RTC_ProgrammingChallenge | /ChallengeProject/coderlane/dockers/repl/empty/Main.rb | UTF-8 | 63 | 2.875 | 3 | [
"MIT"
] | permissive | def say_hello
puts 'Hello, World'
end
5.times { say_hello }
| true |
73293d24d271abc9e0dcff51c7cdcc67c89038e0 | Ruby | Andria177/Ruby0704 | /ex0_02.rb | UTF-8 | 110 | 3.359375 | 3 | [] | no_license | Bonjour ="Bonjour, monde!"
puts Bonjour
Sexy = "Et avec une voix sexy, ça donne:" + Bonjour + " !"
puts Sexy
| true |
81c3c68eec9fb564932fa132430662e415364892 | Ruby | mlkelly/reading-errors-and-debugging-how-tests-work-yale-web-yss-052520 | /calculator.rb | UTF-8 | 219 | 2.59375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Add your variables here
first_number= 2
second_number= 1
sum = first_number + second_number
difference = first_number - second_number
product = first_number*second_number
quotient = first_number/ second_number
| true |
4ef336e162a4ae1f1add07614888d18971af4bae | Ruby | CSheesley/market_1901 | /lib/market.rb | UTF-8 | 1,601 | 3.625 | 4 | [] | no_license | class Market
attr_reader :name, :vendors
def initialize(name)
@name = name
@vendors = []
end
def add_vendor(vendor)
@vendors << vendor
end
def vendor_names
@vendors.map do |vendor|
vendor.name
end
end
def vendors_that_sell(item)
item_seller = []
@vendors.each do |ve... | true |
02f215e11f0ac87a86bec6d19e5001e44c000060 | Ruby | yozdil/TwO-O-Player-Math-Game | /main.rb | UTF-8 | 3,878 | 3.328125 | 3 | [] | no_license | require "./player.rb"
require "./question.rb"
# Game initialization with query of pplayer names
puts `clear`
puts "
▀█▀ █░█░█ █▀█ ▄▄ █▀█ ▄▄ █▀█ █░░ ▄▀█ █▄█ █▀▀ █▀█ █▀▄▀█ ▄▀█ ▀█▀ █░█ █▀▀ ▄▀█ █▀▄▀█ █▀▀
░█░ ▀▄▀▄▀ █▄█ ░░ █▄█ ░░ █▀▀ █▄▄ █▀█ ░█░ ██▄ █▀▄ █░▀░█ █▀█ ░█░ █▀█ █▄█ █▀█ █░▀░█ ██▄
"
puts "Let's start with p... | true |
6538139e5f51dcd923e19ef7b3fc74f96a967204 | Ruby | ancolon2/ruby-on-rails | /Ruby/ruby_learning/numbers.rb | UTF-8 | 1,263 | 4.0625 | 4 | [] | no_license | puts "Simple Calculator"
25.times { print "-"}
puts "Enter the first number"
num_1 = gets.chomp
puts "Enter the second number"
num_2 = gets.chomp
puts "What do you want to do?"
action = gets.chomp
puts "You selected #{action}"
if action =="add"
puts "The first number added by the second number is #{num_1.to_f + num_2... | true |
44b34c18e8d2b1df36df4a90ce6cf5edb2c54268 | Ruby | hboon/purplish-frame | /lib/purplish-frame/ui/view.rb | UTF-8 | 1,786 | 2.546875 | 3 | [
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference",
"BSD-3-Clause"
] | permissive | module PurplishFrame
module View
def left
view_frame.origin.x
end
def left=(x)
f = frame
f.origin.x = x
self.frame = f
end
def right
view_frame.origin.x + view_frame.size.width
end
def right=(right)
f = frame
f.origin.x = right - f.size.width
... | true |
b76bc8eb9f2d0912491d46ef6eaca2c58b4d510a | Ruby | kbuell6919/automationproject | /Rubyproject2/excel_load.rb | UTF-8 | 1,265 | 2.609375 | 3 | [] | no_license | require 'selenium/webdriver'
require 'simple-spreadsheet'
excel_data = SimpleSpreadsheet::Workbook.read("login_data.xlxs")
def cell(row, col, sheet=nil)
sheet = @engine.default_sheet if sheet.nil?
if sheet.is_a? Integer
@engine.cell(row, col, @engine.sheets[sheet - 1])
else
engine_cell = @engi... | true |
5bdc1498474bcab864304d316995b86fbc493575 | Ruby | RossHepburn/Boris-Bikes | /lib/garage.rb | UTF-8 | 230 | 2.8125 | 3 | [] | no_license | require 'bikeContainer'
class Garage
include BikeContainer
def initialize(options = {})
@capacity = 50
self.capacity = options.fetch(:capacity, capacity)
end
def fix_broken_bikes
bikes.each {|bike| bike.fix}
end
end | true |
02f0a4f1870bb8b9a58e522c877cd697e8eab782 | Ruby | bharatagarwal/launch-school | /101_programming_foundations/small_problems/11_medium_2/06.rb | UTF-8 | 586 | 3.875 | 4 | [] | no_license | def valid?(sides)
length_validity = sides.all? do |side|
side > 0 && side < 180
end
length_validity && (sides.sum == 180)
end
def triangle(first, second, third)
sides = [first, second, third]
if valid?(sides)
if sides.include?(90)
:right
elsif sides.any?... | true |
4b6f101cfc94b9aed30a991e3f580011a8d18203 | Ruby | vronnieli/ruby-objects-has-many-through-lab-web-0716 | /lib/song.rb | UTF-8 | 173 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :genre, :artist
attr_reader :title
def initialize (title, genre)
@title = title
@genre = genre
genre.add_song(self)
end
end
| true |
f1bcfbb76a7a7f57da5927c5794a524de03517e3 | Ruby | ifunam/vigilante | /lib/video_builder.rb | UTF-8 | 1,744 | 2.640625 | 3 | [] | no_license | require 'rubygems'
require 'rtranscoder/mencoder'
require 'rtranscoder/ffmpeg'
require File.expand_path(File.dirname(__FILE__) + "/../lib/video_frame_dir")
module VideoTools
class Builder
include RTranscoder
def initialize(frames_path, dir, date, hour, length=10.minutes, frame_type="jpg")
@frames_... | true |
9137ab7e353a55055e962a55877e43ab19f1fc38 | Ruby | GunioRobot/risbn | /lib/risbn.rb | UTF-8 | 569 | 2.71875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # require 'ruby-debug'
# require 'colorize'
# require 'ap'
require 'isbn/tools'
class RISBN
class InvalidISBN < ArgumentError; end
attr_reader :isbn
ISBN_REGEXP = /\b(?=\w)(?:ISBN(?:-1[03])?:? )?(?=[-0-9 ]{17}\b|[-0-9X ]{13}\b(?!\w)|[0-9X]{10}\b)(?:97[89][- ]?)?[0-9]{1,5}[- ]?(?:[0-9]+[- ]?){2}[0-9X]\b/
def... | true |
2e1bcccfa4e0dad14284d96234a90825c4cf4ea5 | Ruby | tetetratra/contest | /abc129/c/c.rb | UTF-8 | 408 | 3.265625 | 3 | [] | no_license | # 4, 0, 608200469
waru = 1_000_000_007 # あまりを出す
n, m = gets.split.map &:to_i # N段目まで行きたい
a = []
while aa = gets # 壊れてる階段
a << aa.to_i
end
# p [n, m]
arr = Array.new(n, -1)
a.each do |aa|
arr[aa] = 0
end
0.upto(n) do |i|
next if arr[i] == 0
if i == 0 || i == 1
arr[i] = 1
next
end
arr[i] = arr[i - ... | true |
65db36dec5762f105090f816d3341e22244a34f5 | Ruby | pegsix/square_array-v-000 | /square_array.rb | UTF-8 | 265 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # def square_array(array)
# array.each do |num|
# num**2
#
# new_numbers = Array.new
# new_numbers << num**2
# end
# end
def square_array(array)
squared = []
array.each do |num|
num**2
squared << num**2
end
squared
end
| true |
5205528cc27233f5c928f536b6317b52a4b905f8 | Ruby | Kite0301/atcoder | /Beginner/008/b.rb | UTF-8 | 195 | 3.109375 | 3 | [] | no_license | n = gets.chomp.to_i
hash = {}
for i in 1..n do
s = gets.chomp.to_s
if hash.include?(s)
hash[s] += 1
else
hash[s] = 1
end
end
puts hash.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }.to_a.first[0] | true |
d59022c579e1831f11b4674552e46c3c7dd17947 | Ruby | i2w/has_content | /lib/has_content/active_record.rb | UTF-8 | 932 | 2.734375 | 3 | [
"MIT"
] | permissive | module HasContent
# has_content concern: allow spcification of content on models
#
# content is a polymorphic association that is laoded on demand, and appears as if it were a normal attribute.
# The advantages being that you can add content to models without modifying the database schema, and that you
# ca... | true |
289f402643ff27638e6ffb36a3c84f08c3150b42 | Ruby | abelsiqueira/dcicpp-research | /2014_05_01/sources/compare.2014.04.24/find.exclusive.rb | UTF-8 | 1,245 | 3.09375 | 3 | [] | no_license | #!/usr/bin/env ruby
def open_cutest(filename)
cutest = {}
open(filename).each_line do |line|
sline = line.split
if sline[0] == "#Name"
next
end
cutest[sline[0]] = {
"ef"=>sline[1],
"time"=>sline[2],
"fval"=>sline[3],
"inf"=>[sline[4].to_f,sline[5].to_f].max
}
end... | true |
d18135e2d5fdbd7d0ae1c575e182f30551109c30 | Ruby | rvwong/netzke-basepack | /lib/netzke/basepack/tree.rb | UTF-8 | 8,965 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Netzke
module Basepack
# Ext.tree.Panel-based component with the following features:
#
# * CRUD operations
# * Persistence of node expand/collapse state
# * (TODO) Node reordering by DnD
#
# == Simple example
#
# class Files < Netzke::Basepack::Tree
# def confi... | true |
411951740a677259c0c093ff6be39ef151fd1605 | Ruby | isabella232/gedcomx-jruby | /lib/gedcomx/iterator.rb | UTF-8 | 401 | 2.65625 | 3 | [
"MIT"
] | permissive |
module Gedcomx
class Iterator
def initialize(input)
unless File.file?(input)
input = Gedcomx.input_stream(input)
end
@iter = org.gedcomx.util.RecordSetIterator.new(input)
end
def has_next?
@iter.hasNext
end
def done?
!@iter.hasNext
end
def next
... | true |
d56404b5ccc4ff6968dd82cd6c939c9e981c38f1 | Ruby | manjarb/ruby_learn | /Ruby_Drill/destructive_methods2.rb | UTF-8 | 1,289 | 3.6875 | 4 | [] | no_license | def destroy_message(string)
#TODO: return the part a string without the message
check_list = /[:]/
if string =~ check_list
stringConvert = string.partition(":").first
test = stringConvert + ":"
return test
else
return string
end
end
def destroy_message!(string)
#TODO: remove the message from string de... | true |
6c7dfb70acc2beace05de5398c989ac02835a5c1 | Ruby | LiveChart/http-digests-ruby | /lib/http_digest_header/digest_list/builder.rb | UTF-8 | 1,108 | 2.671875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module HttpDigestHeader
class DigestList
class Builder
def initialize
@value_map = {}
end
def add(*args)
case args.size
when 1
arg = args.first
case arg
when Digest then add_internal(arg)
when St... | true |
18e47c6d1dca72b7312e1fc527f78818ed52c817 | Ruby | JupiterLikeThePlanet/goby | /lib/Battle/BattleCommand/battle_command.rb | UTF-8 | 868 | 3.296875 | 3 | [
"MIT"
] | permissive | class BattleCommand
# @param [Hash] params the parameters for creating a BattleCommand.
# @option params [String] :name the name.
# @option params [String] :description a summary/message of its purpose.
def initialize(params = {})
@name = params[:name] || "BattleCommand"
@description = params[:descript... | true |
b46d97f0b0f0c5a2f8f9de483d192be92a30b525 | Ruby | ch1c0t/testo | /test/test_contract.rb | UTF-8 | 1,070 | 2.671875 | 3 | [] | no_license | require_relative 'helper'
describe Test do
before do
@test = Test.new do
term 'which changes the state' do
it.instance_eval do
def hello *args
"Hello, #{args.join ' '}."
end
end
greeting = it.hello 'gentle', 'readers'
assert { greeting == 'He... | true |
e0b3b32f23dad8badf96ae459f7fbabea2e349ce | Ruby | vic8722/phase-0 | /week-5/nums-commas/my_solution.rb | UTF-8 | 4,022 | 4.71875 | 5 | [
"MIT"
] | permissive | # Numbers to Commas Solo Challenge
# I spent [] hours on this challenge.
# Complete each step below according to the challenge directions and
# include it in this file. Also make sure everything that isn't code
# is commented in the file.
# 0. Pseudocode
# What is the input?
# input is a positive integer, a fixnum... | true |
e361e700827f32b4ebd2610a49c46c25a5310e7d | Ruby | hercynium/puppet-blkid-info | /lib/puppet/parser/functions/get_blkid_info.rb | UTF-8 | 3,445 | 2.859375 | 3 | [
"MIT"
] | permissive |
module Puppet::Parser::Functions
newfunction(:get_blkid_info, :type => :rvalue, :doc => <<-END
This function returns an array of hashes containing the information gathered
by the blkid_info facter plugin.
*Description:*
If the blkid_info facter plugin is working, this will collect the vars
it set and pr... | true |
a2118d087adabff2357e76a31cba28891ab1da56 | Ruby | onyxraven/pb-downloader | /pb.rb | UTF-8 | 4,410 | 2.515625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'net/ftp'
require 'fileutils'
require 'httpclient'
require 'httpclient/include_client'
require 'trollop'
class Pb
extend HTTPClient::IncludeClient
include_http_client(:method_name => :pbhttp) do |client|
# any init you want
client.connect_timeout = 60
clien... | true |
a78f1ca5fd69821922ebfd57c1b759d541a18493 | Ruby | sa3036/clayoven | /lib/clayoven/claytext.rb | UTF-8 | 5,700 | 3.125 | 3 | [
"MIT"
] | permissive | module ClayText
# These are the values that Paragraph.type can take
PARAGRAPH_TYPES = %i[plain ulitems olitems subheading header footer codeblock images horizrule mathjax].freeze
HTMLESCAPE_RULES = {
"&" => "&",
"<" => "<",
">" => ">",
}.freeze
ROMAN_NUMERALS = {
10 => "x",
9 =... | true |
3690c06a64b141cb33b4ac1880c15021f191d887 | Ruby | rec0de/matasano | /2-15.rb | UTF-8 | 261 | 2.90625 | 3 | [
"MIT"
] | permissive | require_relative "matasano"
puts Matasano.unpadd("ICE ICE BABY\x04\x04\x04\x04").inspect
# Throws "Invalid Padding" exception
begin
puts Matasano.unpadd("ICE ICE BABY\x05\x05\x05\x05").inspect
rescue => exception
puts "Exception: " + exception.inspect
end | true |
b0fc902f5a8ebc1674b0a77d2067b051c54f0b57 | Ruby | delongtj/project_euler | /test/test_fibonacci_sequence.rb | UTF-8 | 1,887 | 3.3125 | 3 | [] | no_license | require 'test_helper'
class TestFibonacciSequence < Minitest::Test
def test_that_constructor_requires_a_positive_integer
assert_raises "Invalid maximum" do
@fibonacci_sequence = FibonacciSequence.new(maximum: -1)
end
assert_raises "Invalid maximum" do
@fibonacci_sequence = FibonacciSequence... | true |
3b4a55ef9663cddca3c5cb395943fcf0eec3cab8 | Ruby | barlowlee/sample_app5 | /example_user.rb | UTF-8 | 403 | 3.109375 | 3 | [] | no_license | #example_user.rb
class User
# attr_accessor :name, :email
# Getters
def name
name = @name
end
def email
email = @email
end
# Setters
def name=(thing)
@name = thing
end
def email=(thing)
@email = thing
end
def initialize(any_particular_user = {})
@name = any_particular_user[:name]
@email = any_... | true |
55b085b9f5ffdddf3d8d1fbc9fa6526b940a36cc | Ruby | lbvf50mobile/til | /20220916_Friday/20220916.rb | UTF-8 | 769 | 3.203125 | 3 | [] | no_license | # Leetcode: 1770. Maximum Score from Performing Multiplication Operations.
# https://leetcode.com/problems/maximum-score-from-performing-multiplication-operations/
# @param {Integer[]} nums
# @param {Integer[]} multipliers
# @return {Integer}
# TLE.
def maximum_score(nums, multipliers)
# Based on.
# https://leetcod... | true |
6d32a0b6bcf187ef00515e100ecb74259a9dbcf9 | Ruby | codewithirene567/looping-while-until-onl01-seng-ft-050420 | /lib/until.rb | UTF-8 | 98 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_until
levitation = 6
until levitation == 10
levitation += 1
puts "Wingardium Leviosa"
end
end
| true |
6c1c29b8b007162a1a9bf4d514ea9989d3db6b82 | Ruby | lxzylllsl/songjiang_weather_wechat | /app/helpers/air_quality_helper.rb | UTF-8 | 1,935 | 2.671875 | 3 | [] | no_license | module AirQualityHelper
def transform_aqi level
"<div class='col-xs-10 aqi-level-shadeguide #{translate_level(level)}'>#{level}</div>"
end
def aqi_format kpi
match = /([a-zA-Z]+)([0-9,.]+)/.match kpi
if match.present?
"#{match[1]}<span class=\"kpi-small\">#{match[2]}</span>".html_safe
else... | true |
0cd37e81c26a7765eddb8319ae74b7997c15be98 | Ruby | paddor/cztop | /lib/cztop/config/comments.rb | UTF-8 | 1,740 | 2.796875 | 3 | [
"ISC"
] | permissive | # frozen_string_literal: true
module CZTop
class Config
# Access this config item's comments.
# @note Note that comments are discarded when loading a config (either from
# a string or file) and thus, only the comments you add during runtime
# are accessible.
# @return [CommentsAccessor]
... | true |
5604bd1b11b61303e745fe4b19943bd7076d2f45 | Ruby | TomasOyarzun/E8CP1A1 | /ejercicio2.rb | UTF-8 | 213 | 3.15625 | 3 | [] | no_license | #Crear un método que lea el archivo, lo abra y devuelva la cantidad de líneas que posee.
def count_lines(filename)
File.open(filename, 'r'){ |file| file.readlines.count }
end
puts count_lines('peliculas.txt') | true |
49afd2ccdced2257a418ca0e672095bf7224380d | Ruby | RossMelville/Final-Project-Golf-Api | /db/seeds.rb | UTF-8 | 14,615 | 2.625 | 3 | [] | no_license |
Hole.delete_all()
Round.delete_all()
Shot.delete_all()
Course.delete_all()
c0 = Course.create({name: ""})
c1 = Course.create({name: "Dundas Parks"})
c2 = Course.create({name: "Ratho Park"})
r1 = Round.create({course_id: c1.id, date: "2017-10-07"})
h1 = Hole.create({course_id: c1.id, number: 1, par: 4, green_f... | true |
dd7081d16e0c5ad3c367d643730c2bafb00c66ad | Ruby | NavyAnt24/active_record_lite | /active_record_lite-active-record-skeleton/lib/active_record_lite/sql_object.rb | UTF-8 | 2,189 | 2.828125 | 3 | [] | no_license | require_relative './associatable'
require_relative './db_connection'
require_relative './mass_object'
require_relative './searchable'
require 'active_support/inflector'
class SQLObject < MassObject
extend Searchable
db = DBConnection.open("cats.db")
def self.set_table_name(table_name)
@table_name = table_na... | true |
9802f962458ccf7c604141d877a26e86ad4f553a | Ruby | pragnesh/bigbananajour | /lib/bigbananajour/eater.rb | UTF-8 | 2,169 | 2.75 | 3 | [
"MIT"
] | permissive | class Bananajour::Eater
def initialize
@browser = Bananajour::Bonjour::RepositoryBrowser.new
end
def go!
$stderr.puts "Starting the EATER!!!"
while true do
@browser.repositories.each do |remote_repo|
$stderr.puts "Eater has seen remote repo '#{remote_repo}'"
local_repo = Bananajo... | true |
58cb382141a8894af3bac9ef6d1ae247bc14c0fb | Ruby | viperior/wordmind | /wordmind.rb | UTF-8 | 705 | 3.046875 | 3 | [] | no_license | require 'CSV'
Dir["./lib/*.rb"].each {|file| require file}
display_header_animation(8, 0.1, 88)
dictionary = WMDictionary.new()
first_run = true
loop do
if (first_run)
input = 1
first_run = false
else
puts "1) New game"
puts "2) Exit"
input = gets.chomp.to_i
end
case input
when 1
... | true |
418a965bae17c19f513f0f17f1bd0a73b730ada1 | Ruby | acant/rspec-mocks | /lib/rspec/mocks/verifying_proxy.rb | UTF-8 | 2,637 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'rspec/mocks/verifying_message_expecation'
module RSpec
module Mocks
# A verifying proxy mostly acts like a normal proxy, except that it
# contains extra logic to try and determine the validity of any expectation
# set on it. This includes whether or not methods have been defined and the
# a... | true |
f5721361345c27b38ff00f6e2a8a19d9442d3df1 | Ruby | SpencerLindemuth/NYSE-Watch | /lib/Models/user_stock_research_menu.rb | UTF-8 | 1,373 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def user_stock_research_menu(rerun = 0)
if rerun == 1 || rerun == 0
system('clear')
end
if rerun == 2
puts 'Please enter stock symbol or stock name to lookup or type "back" to go back'
input = gets.chomp
if valid_symbol?(input)
user_stock_profile_menu(input)
... | true |
c883d89263b30d807414c3e3cf23f49abf74720c | Ruby | krishnaagarwal1994/Scripting | /XCodeTarget.rb | UTF-8 | 1,731 | 3.03125 | 3 | [] | no_license | require './XCodeFile'
# Represents a target in a XCode project
class XCodeTarget
attr_reader :name, :is_test_target
# Initializer that takes an XcodeTarget as an input
def initialize(target)
@target = target
@name = target.display_name
@is_test_target = target.test_target_type?
end
# Returns an... | true |
8139bee1e6b48307b0b53f712cd3084b9ac17f7a | Ruby | Kel4545/Assessment-7 | /lib/users_table.rb | UTF-8 | 343 | 2.703125 | 3 | [
"MIT"
] | permissive | class UsersTable
def initialize(connection)
@database_connection = connection
end
def create(username, message)
@database_connection.sql("INSERT into users (username, message) values ('#{username}', '#{message}') returning id").first["id"]
end
def find
@database_connection.sql("SELECT * from use... | true |
665011f41a4dbf1f687cadf28022c0aa2747e61e | Ruby | kamkha/ruby-wordnet | /spec/wordnet/synset_spec.rb | UTF-8 | 4,267 | 2.5625 | 3 | [
"LicenseRef-scancode-wordnet"
] | permissive | #!/usr/bin/env ruby
BEGIN {
require 'pathname'
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
libdir = basedir + 'lib'
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
}
require 'rspec'
require 's... | true |
ae4797eb89368e619bc131c7fa34139287e7c4db | Ruby | Aperions/StockScoreboard | /database_persistence.rb | UTF-8 | 3,301 | 2.765625 | 3 | [] | no_license | require "pg"
require "date"
class DatabasePersistence
def initialize(logger)
@db = if Sinatra::Base.production?
PG.connect(ENV['DATABASE_URL'])
else
PG.connect(dbname: "stock_scoreboard")
end
@logger = logger
end
attr_accessor :table_sort
def query(stateme... | true |
a70411734504af95b6495b3ca5e96864c4fb8a49 | Ruby | swagdaddy56/ipsum_generator | /app.rb | UTF-8 | 1,348 | 2.640625 | 3 | [] | no_license | require 'sinatra'
require 'dinosaurus'
Dinosaurus.configure do |config|
config.api_key = '9fb9156eefee8f66d8d35da03e4f41f1'
end
get '/swag' do
redirect 'page.html'
end
post '/send' do
@content = []
@word = params['word']
@numb = params['num']
@results = Dinosaurus.lookup(@word)
@syn = Dinosaurus.synon... | true |
0f9e2caa0cde0fc5e5f4ee7b1fe7c9df55aaa146 | Ruby | jtippit223/programming-univbasics-4-array-concept-review-lab-online-web-prework | /lib/array_methods.rb | UTF-8 | 426 | 3.609375 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def find_element_index(array, value_to_find)
array.length.times { |index|
if array[index]==value_to_find
return index
end
}
return nil
end
def find_max_value(array)
c = 0
array.length.times do |index|
if array[index] > c
c = array[index]
end
c
end
def find_min_value(array)... | true |
63aca3ceb84c0bc4fc554c30faa585d12931f3a7 | Ruby | dmarkow/word_ref | /lib/word_ref/client.rb | UTF-8 | 667 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'faraday'
require 'faraday_middleware'
module WordRef
API_KEY = ENV['WORDREF_API_KEY']
class Client
attr_accessor :result
attr_accessor :conn, :response
def initialize
@conn = Faraday.new(:url => "http://api.wordreference.com/#{API_KEY}/json") do |builder|
builder.response :logge... | true |
539388fa97a3977101796a5923df427fade4274b | Ruby | janlucaberger/W3D5 | /active_record/lib/00_attr_accessor_object.rb | UTF-8 | 377 | 3.015625 | 3 | [] | no_license | require 'byebug'
class AttrAccessorObject
def self.my_attr_accessor(*names)
puts names
names.each do |name|
attr_get = name
attr_set = (name.to_s + "=").to_sym
define_method(attr_set) do |val|
self.instance_variable_set("@#{name}", val)
end
define_method(attr_get) { se... | true |
6060cd416b49d23b64dc91527d3e923505f38084 | Ruby | matthewkiefer/LS-RB100-Exercises | /hashes/hash_loops.rb | UTF-8 | 382 | 3.640625 | 4 | [] | no_license | # hash_loops
person = {name: 'Bob', occupation: 'web developer', hobbies: 'painting'}
puts person.keys
puts person.values
# puts "And here are both: " + person.each_key { |key| puts key} + person.each_value { |value| puts value }
person.each {|key, value| puts key }
person.each {|key, value| puts value }
person.eac... | true |
2b44be4329f563c9144f78096d82e3d787f8aca0 | Ruby | TimRobinson1/student-directory | /directory.rb | UTF-8 | 3,514 | 4.25 | 4 | [] | no_license | @students = []
require 'CSV'
def student_input_loop(name)
while !name.empty? do
# Add the student hash to the array
student_list(name)
puts "Now we have #{@students.count} students"
# Get another name from the user
name = STDIN.gets.chomp
end
puts "Students added. We now have a total of #{@st... | true |
8f08f54f9c9e5e2e4fdb22cfcf0efc397ed57d6f | Ruby | austenjohnson/ruby-warmups | /morse_code.rb | UTF-8 | 2,021 | 4.34375 | 4 | [] | no_license | # Write a program that automatically converts English text to Morse code and vice versa.
require 'pry'
@morse_dict = { "a" => ".-","b" => "-...","c" => "-.-.","d" => "-..","e" => ".","f" => "..-.","g" => "--.","h" => "....","i" => "..","j" => ".---","k" => "-.-","l" => ".-..","m" => "--","n" => "-.","o" => "---","p" =... | true |
44e5cfb155acadc9138893fa18aaa48c4286a642 | Ruby | jiahut/tools | /api-client/jf.net.rb | UTF-8 | 3,567 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'unirest'
require 'digest'
require 'cgi'
require 'json'
require 'openssl'
require 'base64'
PUBLIC_KEY_FILE = 'pub.key'
def encrypt(origin_string)
public_key = OpenSSL::PKey::RSA.new(File.read(PUBLIC_KEY_FILE))
encrypted_string = Base64.encode64(public_key.public_encrypt(origin_string)... | true |
a7da831a19ae0be000ea6a659cda9599343daa7c | Ruby | mailgun/mailgun-ruby | /lib/mailgun/domains/domains.rb | UTF-8 | 3,880 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | require 'mailgun/exceptions/exceptions'
module Mailgun
# A Mailgun::Domains object is a simple CRUD interface to Mailgun Domains.
# Uses Mailgun
class Domains
# Public: creates a new Mailgun::Domains instance.
# Defaults to Mailgun::Client
def initialize(client = Mailgun::Client.new)
@clien... | true |
eaf9fa7cbc0a1bec7addda9083295e1f95a3ea14 | Ruby | wyaeld/authenticating-proxy | /lib/proxy.rb | UTF-8 | 1,700 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'rack/proxy'
class Proxy < Rack::Proxy
attr_accessor :upstream_url
def initialize(app, upstream_url)
@app = app
@upstream_url = URI(upstream_url)
super(backend: upstream_url, streaming: false)
end
def call(env)
path = env['PATH_INFO']
if proxy?(path)
authenticate!(env)
... | true |
17e13072ba734d0819cb597b1b3077c954d52d62 | Ruby | HomeBusProjects/ruby-homebus-application | /lib/homebus_app_options.rb | UTF-8 | 2,139 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'optparse'
# based on Jake Gordon's excellent article, "Daemonizing Ruby Processes"
# https://codeincomplete.com/posts/ruby-daemons/
class HomeBusAppOptions
attr_reader :options
def initialize
@options = {}
daemonize_help = 'run daemonized in the background (default: false)'
pidfile_h... | true |
8d396b527e2460e56b65b33c941679dddc3a985a | Ruby | amhall25/ruby-objects-has-many-through-lab-online-web-pt-090819 | /lib/appointment.rb | UTF-8 | 243 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Appointment
attr_accessor :time, :doctor, :patient
@@all =[]
def initialize (time, patient, doctor)
@time= time
@doctor = doctor
@patient = patient
@@all << self
end
def self.all
@@all
end
end
| true |
7e6b49776c4867b485f4ad8b89aa4871785de72a | Ruby | damilola-dealdey/AdvanceRuby | /AdvEx-6/bin/main.rb | UTF-8 | 488 | 3.515625 | 4 | [] | no_license | require_relative "../lib/string"
print "Enter desired string : "
str = Mystring.new(gets)
#puts str
print "Enter the desired method's name' : "
method_name = gets.chomp
# puts substr
# puts str.include? substr
begin
puts eval("str.#{method_name}")
rescue => exception
puts exception
end
#puts str.send(:exclu... | true |
4f4ac25253ae068813183756b8f5181250d0fb9d | Ruby | adi3/practice_ruby | /squared.rb | UTF-8 | 95 | 3.46875 | 3 | [] | no_license | class Numeric
def squared
return self * self
end
end
puts 9.squared
puts 16.squared | true |
f0a67015565ffbdbf641fa4071296f0e6463b02a | Ruby | philiplambok/cpractice | /codeforces/hotelier.rb | UTF-8 | 765 | 3.78125 | 4 | [] | no_license | def find_zero_index_from_left(array)
found_index = nil
array.each_with_index do |element, index|
if element.eql?(0)
found_index = index
break
end
end
found_index
end
def find_zero_index_from_right(array)
found_index = nil
(array.size - 1).downto(0).each do |index|
if array[index].eq... | true |
f5eac7c39f6b41495268a6bddb6dcb343b16bc1e | Ruby | bobuel/durham_webpage | /app/models/plant.rb | UTF-8 | 315 | 2.609375 | 3 | [] | no_license | class Plant < ActiveRecord::Base
before_create :set_area_volume
def set_area_volume
self.area = length * width
self.volume = area * height
end
validates :name, presence: true, uniqueness: true
validates :length, presence: true
validates :width, presence: true
validates :height, presence: true
end
| true |
921455e06a8e6dd5bcfe93800377ec7079b48654 | Ruby | blt/mad_chatter | /lib/mad_chatter/actions/rename.rb | UTF-8 | 623 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module MadChatter
module Actions
class Rename < MadChatter::Actions::Base
@@regex = /\/nick (.+)/
def handle(message)
if message.filtered_text =~ @@regex
old_username = message.username
username = parse_username(message.filtered_text)
MadChatter::Use... | true |
54b9fe6c5eb46d9202c74c3f315bcdb51349caf9 | Ruby | jessgenualdi/exercises | /class_exercise.rb | UTF-8 | 312 | 3.265625 | 3 | [] | no_license | input = File.open('./weather.dat', File::RDONLY){|f| f.read }
array = input.lines.map(&:split)
2.times do
array.shift
end
array.pop
temp_min = 0
temp_max = 1000
array.each do |line|
difference = line[1].to_i - line[2].to_i
p difference
if difference < temp_max
temp_max = difference
end
end
| true |
7f57a8e6edd79aca1ce348160406dacbe383cd09 | Ruby | deborahleehamel/character_counting | /lib/count_characters.rb | UTF-8 | 609 | 4.03125 | 4 | [] | no_license | class CountCharacters
def initialize(string)
end
def formatted_counts
"a: 3\n" +
"b: 2\n" +
"c: 1\n"
end
end
# count the characters in the argument
# how do I want to count the characters? - maybe a class for that
# make a thing that counts characters 'CountCharacters.new' -
# give it a string/inp... | true |
2990293754af51a09d9b49a5c84e5ec817e27790 | Ruby | Chesza-Chesza/PracticesRubyCycles | /3_s_to_m.rb | UTF-8 | 441 | 3.421875 | 3 | [] | no_license | seconds= [100, 50, 1000, 5000, 1000, 500]
=begin
def to_minutes(seconds)
resolve = []
seconds.size.times do |i|
minutes = seconds[i] / 60.00
resolve.append(minutes.ceil(3))
end
return resolve
end
print "Segundos a minutos: #{to_minutes(seconds)}"
=end
def to_minutes(seconds_array)
... | true |
620d4f0709162b91775a653d9076ec70b61e6ce4 | Ruby | mac718/Launch_School | /lesson_5/twenty_one.rb | UTF-8 | 3,987 | 4.28125 | 4 | [] | no_license | require 'pry'
SUITS = ['C', 'S', 'H', 'D'].freeze
CARDS = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace'].freeze
MAX = 21
STAY = 17
def initialize_deck
deck = []
SUITS.each do |suit|
CARDS.each do |card|
deck << [suit, card]
end
end
deck
end
def deal_cards(player_hand, dealer_hand... | true |
fa9d6bf44e346cc22af3b915516e5616460a126e | Ruby | dman30/shapefile-webservice | /lib.rb | UTF-8 | 637 | 3.015625 | 3 | [] | no_license | require 'rgeo'
require 'rgeo-shapefile'
require 'pry'
class Converter
def self.latlon2plz lat, lon
result = query_file lat, lon
if result.nil? then return {} end
convert_to_json result
end
private
def self.convert_to_json result
result.attributes
end
def self.query_file lat, lon
fa... | true |
2aedc1b8ff89837d33739c9d49f9bb7f362c50c8 | Ruby | superninjamonkey26/programming-univbasics-4-array-simple-array-manipulations-online-web-prework | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 1,369 | 3.375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_push(array, string)
array = ["red", "orange", "yellow", "green", "blue", "indigo"]
array.push("violet")
end
def using_unshift(array, string)
array = ["Brooklyn", "Queens", "Manhattan", "Bronx"]
array.unshift("Staten Island")
end
def using_pop(array)
array = array.pop(1)
array.pop
end
def pop_wi... | true |
4b3a83a77812c48a57f8c9bdcd9f3fb1c21e2fd8 | Ruby | mronauli/enigma_1911 | /test/offset_test.rb | UTF-8 | 709 | 2.90625 | 3 | [] | no_license | require './test/test_helper'
require './lib/offset'
class OffsetTest < Minitest::Test
def test_offset_exists
offset = Offset.new("010419")
assert_instance_of Offset, offset
end
def test_offset_has_a_date
offset = Offset.new("010419")
assert_equal "010419", offset.date
end
def test_can_squar... | true |
3cfa72cb3488cc38ec6eba625e326e36d3f82d03 | Ruby | mikeodell77/christmas-picker | /person_spec.rb | UTF-8 | 615 | 2.828125 | 3 | [] | no_license | require './person'
RSpec.describe Person, "#can_buy_for" do
context "with no params" do
it "throws an exception" do
person = Person.new(name: "Mike", exclude: [])
expect{person.can_buy_for?}.to raise_error(ArgumentError)
end
end
context "with params" do
it "returns true" do
... | true |
dbdafff822dbcf83fbe6274cee965271df0e05ca | Ruby | Jaimedsf/Ruby-Puro | /POO/atributos/atributos.rb | UTF-8 | 144 | 3.296875 | 3 | [] | no_license | class Dog
attr_accessor :name, :age
end
dog = Dog.new
dog.name = 'Marlon'
puts dog.name
dog.age = '1 ano'
puts dog.age | true |
f91fd12d2e9c1342c7ad386afa1993de215c9f70 | Ruby | kdar/challenges | /hackerrank/challenges/Ruby/Methods/ruby_methods_introduction.rb | UTF-8 | 269 | 3.828125 | 4 | [] | no_license | def prime?(n)
if n <= 1
return false
elsif n < 3
return true
elsif n % 2 == 0 or n % 3 == 0
return false
end
i = 5
while i*i <= n do
if n % i == 0 or n % (i+2) == 0
return false
end
i += 6
end
true
end
| true |
4c8f251ab78f7f7b4e133edc9eb540171dd2c49e | Ruby | charleszardo/ruby-games | /arcade.rb | UTF-8 | 632 | 2.6875 | 3 | [] | no_license | games = {
1 => {
name: "Battleship",
path: "battleship"
},
2 => {
name: "Chess",
path: "chess"
},
3 => {
name: "Ghost",
path: "ghost"
},
4 => {
name: "Hangman",
path: "hangman"
},
5 => {
name: "Mastermind",
path: "mastermind"
},
6 => {
name: "Memory",
... | true |
3644eb5ced14c79e583f5f558229e495a2525581 | Ruby | rkiel/serverless-starter | /lib/create/commander.rb | UTF-8 | 2,421 | 2.75 | 3 | [] | no_license | require 'optparse'
require 'ostruct'
require 'json'
module Create
class Commander
attr_accessor :options
def initialize (argv)
@options = OpenStruct.new
options.debug = false
options.template = "aws-nodejs"
@option_parser = OptionParser.new do |op|
op.banner = "Usage: cre... | true |
f05b98c28895f2345dc6a6c9c9c9a463958e2be1 | Ruby | jerryq27/CodeEval | /src/EasyLevel/Ruby/OddNumbers.rb | UTF-8 | 113 | 3.640625 | 4 | [] | no_license | def print_odd_numbers(limit = 99)
for i in 1..limit
if i % 2 != 0
puts i
end
end
end
print_odd_numbers | true |
5cb38ceee2c6c7a8bf9f8ecbd2acbde60031ba0b | Ruby | fatwebdev/thinknetica_1 | /Lesson_08/wagon.rb | UTF-8 | 674 | 3.328125 | 3 | [] | no_license | # frozen_string_literal: true
class Wagon
include Manufacturer
attr_reader :full_capacity, :number
attr_reader :occupied
def initialize(full_capacity)
@full_capacity = full_capacity
@occupied = 0
@number = rand(36**8).to_s(36).upcase
validate!
end
def valid?
validate!
true
res... | true |
a06cb6dc1323f7fa65610340b50defcb5e0c453e | Ruby | psave/lighthouse_git | /wk2_day4/robots/lib/plasma_cannon.rb | UTF-8 | 181 | 2.75 | 3 | [] | no_license | class PlasmaCannon < Weapon
attr_reader :name, :weight, :damage
def initialize
super('Plasma Cannon', 200, 55)
end
def hit(robot)
robot.wound(damage)
end
end | true |
1bcc348ac3c60d100293a030e241bbc797158ca3 | Ruby | kosbrother/mongmongwoo | /app/services/price_manager_for_cart.rb | UTF-8 | 1,231 | 2.71875 | 3 | [] | no_license | class PriceManagerForCart
include CalculatePrice
attr_reader :cart_items, :items_price, :shopping_point_amount, :reduced_items_price, :campaigns, :total_discount_amount, :shopping_point_campaigns, :ship_fee, :ship_campaign, :total
def initialize(cart)
@cart_items = cart.cart_items.includes({item: :specs}, :... | true |
79c09cd99cbae469be6a88c24cbf57713c09751c | Ruby | 7eXx/aoc2020 | /13/script.rb | UTF-8 | 648 | 2.9375 | 3 | [] | no_license | notes = File.open('data.txt', 'r').map{ |l| l.strip }
arrival = notes[0].to_i
times = notes[1].split(',').filter { |l| l != 'x' }.map(&:to_i)
next_stop = times.map { |t| { t: (arrival / t + 1) * t, bus: t } }.min { |a, b| a[:t] <=> b[:t] }
puts '# Day 13 - Part 1:'
puts (next_stop[:t] - arrival) * next_stop[:bus]
li... | true |
a787c91f9c9a302e6a00bdbe246bfde9fd168bb3 | Ruby | aerohit/learningtocode | /ruby/wellgrounded/ch03/ticket.rb | UTF-8 | 945 | 3.6875 | 4 | [] | no_license | class Ticket
VENUES = ["Convention Center", "Fairgrounds", "Town Hall"]
def initialize(venue, date)
if VENUES.include?(venue)
@venue = venue
else
raise ArgumentError, "Unknown venue #{venue}"
end
@date = date
end
def venue
@venue
end
def date
@date
end
def price=... | true |
b55c778087b2ae6f983efccd7c2d5024c444f12a | Ruby | GoodGuyGregory/Ruby | /ruby_gems/money_example.rb | UTF-8 | 195 | 3.171875 | 3 | [] | no_license | # First step in importing a gem is requiring it
require 'money'
money = Money.new(1000, "USD")
more_money = Money.new(1000, "USD")
all_the_money = money + more_money
puts all_the_money.inspect | true |
fc5491f5b7bf3046ff405ef1b8be034d5a0aa55e | Ruby | ecclestimothy87/gem_console | /lib/gem_console/console.rb | UTF-8 | 477 | 2.6875 | 3 | [
"MIT"
] | permissive | module GemConsole
module X
def y
:y
end
end
module Console
include GemConsole
help :my_method, "Call ma method, bro!"
help :exit, "Exit, bro!"
def project_name
"#{GemConsole} v.#{GemConsole::VERSION}"
end
def setup
puts "setting up..."
... | true |
f79ac86de88aa347378ca4b6389776be61886c55 | Ruby | ryanmcgarvey/Ryan-goes-to-training | /rails2_studio/code/om/define_method_method.rb | UTF-8 | 346 | 3.59375 | 4 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | #START:impl
class Parent
def fred
puts "Yabba Dabba Do!"
end
end
class Child < Parent
define_method(:barney, instance_method(:fred))
end
#END:impl
#START:body
c = Child.new
c.fred # >> Yabba Dabba Do!
c.barney # >> Yabba Dabba Do!
p = Parent.new
p.fred # >> Yabba Dabba Do!
p.barney # undefined ... | true |
03c50a82497ce547f0a0459080677de3ef5f7835 | Ruby | SciRuby/mdarray | /lib/mdarray/ruby_operators.rb | UTF-8 | 6,274 | 2.5625 | 3 | [
"NetCDF",
"BSD-2-Clause"
] | permissive | # -*- coding: utf-8 -*-
##########################################################################################
# Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
# and distribute this software and its documentation, without fee and without a signed
# licensing agreement, i... | true |
e36f93fe0659f6ad997f546a67065ad767508dc6 | Ruby | rhys117/LaunchSchoolCurriculum | /Backend/challenges/completed/word_count.rb | UTF-8 | 328 | 3.625 | 4 | [] | no_license | class Phrase
attr_reader :word_count
def initialize(str)
@input = str
@word_count = convert_input_to_count
end
def convert_input_to_count
word_count = Hash.new(0)
word_array = @input.downcase.scan(/\b[\w']+\b/)
word_array.each do |word|
word_count[word] += 1
end
word_count
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.