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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2f1b11d6115b30c6d4e82a457892e893897c1a97 | Ruby | Aurite/twitterlyzer | /analysis/wordnet/word_analysis.rb | UTF-8 | 2,612 | 3 | 3 | [] | no_license | require 'rubygems'
require 'wordnet'
require 'nokogiri'
require 'cgi'
require 'open-uri'
@toplevel = ["politics", "technology", "recreation", "medium", "entertainment", "education", "fashion", "business", "travel", "health"]
words = []
File.readlines("groups.txt").each do |line|
words << line.sub!(/\n/,"")
end
words +... | true |
14d2d6084efa857459732b8d3f2c2e5563c1c1c4 | Ruby | l0rellei/gatherer | /app/models/task.rb | UTF-8 | 539 | 3.1875 | 3 | [] | no_license | class Task
attr_accessor :size, :completed_at
def initialize(options = {}) #give a hash as argument
mark_completed(options[:completed_at]) if options[:completed_at]
# @completed = options[:completed]
@size = options[:size]
end
def mark_completed(date = Time.current)
@completed_at = date
end
def complete... | true |
5b21f805ca18a17c796394ed9abbb76cb249ee17 | Ruby | chrisb3546/Rick-and-Morty-Character-app | /lib/project/cli.rb | UTF-8 | 1,622 | 3.46875 | 3 | [
"MIT"
] | permissive | class Cli
def run
input = " "
API.get_characters
while input != "exit"
puts " "
puts "Welcome to the Rick and Morty character app!"
puts " "
puts "To see a list of characters names, type 'names'"
puts " "
puts "To learn what a ch... | true |
d2bb6d7bf24252f98954a856e9cbe2a56bba3d8f | Ruby | sonataFarm/algorithms | /week-7/hw/outcast.rb | UTF-8 | 364 | 3.21875 | 3 | [] | no_license | require './word-net'
class Outcast
def initialize(wordnet)
@wordnet = wordnet
end
def outcast(nouns)
distances = nouns.map { |n| compute_sum_of_distances(n, nouns) }
nouns[distances.each_with_index.max[1]]
end
private
def compute_sum_of_distances(from, nouns)
nouns.map { |to| @wordne... | true |
d56eb7236f82b1fa66f0c4657809466271f27840 | Ruby | DouglasAllen/code-Metaprogramming_Ruby | /raw-code/PART_II_Metaprogramming_in_Rails/gems/pry-0.9.12.2/lib/pry/method/disowned.rb | UTF-8 | 1,858 | 3.125 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Metaprogramming Ruby",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http:/... | true |
40fb51358277cd1ffea500c7bc15ad15297a5d1e | Ruby | johnjmarks4/git_test | /test.rb | UTF-8 | 112 | 2.859375 | 3 | [] | no_license | def greet
puts "Hello world"
puts "How are you today?"
puts "I myself am fine"
puts "And you?"
end
greet | true |
f4dc8d2a85394e04d5143809c003184c48a586b1 | Ruby | inbarshani/carmen | /app/models/country.rb | UTF-8 | 402 | 2.640625 | 3 | [] | no_license | class Country < ActiveRecord::Base
serialize :flag,Array
serialize :museum_clues,Array
serialize :library_clues,Array
attr_reader :flag
=begin
maybe need to override initialize to init arrays to []
=end
def museum_clue
index = rand(1..@museum_clues.length)
@museum_clues[index]
end
def library_c... | true |
feffb79c74cd26155942062b9f57c6443a3e258a | Ruby | rabidpraxis/carbon-copy | /spec/request_spec.rb | UTF-8 | 2,767 | 2.53125 | 3 | [] | no_license | require "spec_helper"
require "carbon-copy/request"
module CarbonCopy
describe Request do
describe "#parse_headers" do
let(:rs) { Request.new(double) }
it "should parse easy header strings" do
st = StringIO.new
st << "TestHeader: Header Result"
st << "\r\n\r\n"
st.rew... | true |
cc8defe8ec56c196f1bbb71a37e57c70bf9ce8a4 | Ruby | bunnymatic/exercism-exercises | /ruby/rna-transcription/rna_transcription.rb | UTF-8 | 467 | 2.65625 | 3 | [] | no_license | class Complement
LUT = {
"C" => "G",
"G" => "C",
"T" => "A",
"A" => "U"
}
def self.of_dna(amino_acids)
transformed = amino_acids.split("").map{|amino_acid| LUT[amino_acid]}
return "" if !transformed.all?
transformed.join
end
class << self
private
def translate_amino_acid... | true |
32f14f7ba10b7f8a32713e723533528600ea8fe8 | Ruby | masa21kik/atcoder | /contest/abc162/d.rb | UTF-8 | 396 | 2.875 | 3 | [
"MIT"
] | permissive | N = gets.chomp.to_i
S = gets.chomp
IDX = {"R"=>[], "G"=>[], "B"=>[]}
0.upto(N-1) do |i|
IDX[S[i]] << i
end
ng = Hash.new(0)
IDX["R"].each do |i|
IDX["G"].each do |j|
a, b = [i, j].sort
gap = b - a
ng[(a+b)/2] += 1 if gap.even?
ng[a-gap] += 1
ng[b+gap] += 1
end
end
ans = IDX["R"].size * IDX... | true |
d3a7c96ea10876dfad9efd6140954ce81aaafc5b | Ruby | piotr-galas/play-with-ruby | /simple_delegator.rb | UTF-8 | 459 | 3.375 | 3 | [] | no_license | require 'delegate'
class Order
def method1
puts 'method1'
end
def method2
puts 'method2'
end
end
class OrderWithDiscount < SimpleDelegator
def discount
puts 'discount'
end
end
# all method from Order class are available in OrderWithDiscount
# to achevie it, make class inherit SimpleDelegato... | true |
ab18ad3a50ab1212985d5e0529e7f7fd844b6320 | Ruby | katryc/a9n | /lib/a9n/ext/hash.rb | UTF-8 | 681 | 2.59375 | 3 | [
"MIT"
] | permissive | module A9n
class Hash
class << self
def deep_prepare(hash, scope)
hash.inject({}) do |result, (key, value)|
result[(key.to_sym rescue key)] = get_value(key, value, scope)
result
end
end
def merge(*items)
return nil if items.compact.empty?
item... | true |
911285ccc61fe0c7cf38fe99e82ec220ab95df9f | Ruby | liveseasonal/animal-inheritence | /bats.rb | UTF-8 | 278 | 2.90625 | 3 | [] | no_license | require_relative 'moduleflight'
require_relative 'mammal'
class Bat < Mammal
include Flight
def initialize(multicelluar, vertabrae, hair)
super(multicelluar, vertabrae, hair)
@wings = 2
end
end
batty = Bat.new(true, true, "super hairy")
batty.fly | true |
df6582a387d64336aed6288a53653106257d8753 | Ruby | stellawi/ruby-introduction | /basic-1/math.rb | UTF-8 | 59 | 2.84375 | 3 | [] | no_license | puts -23.abs
puts 12.div(2)
puts 12.modulo(7)
puts 100.to_s | true |
0371a566c70b3c220aad4be6df520d4c8a87d204 | Ruby | vinukrishnan3694/Ruby-download-unzip-sort | /write_to_file.rb | UTF-8 | 158 | 2.625 | 3 | [] | no_license |
require 'rubygems'
class WriteToFile
def write_to_file(content,file_name)
File.open(filename, 'w') { |file| file.puts(content) }
end
end | true |
c99c8a7a32311526244155a7fa7e77ebbad22e0a | Ruby | screamingmonkeys/website | /app/models/feed.rb | UTF-8 | 850 | 2.640625 | 3 | [] | no_license | class Feed
require 'rss/2.0'
require 'open-uri'
require 'htmlentities'
def get_data(url)
# Default text
feed_data = "<h2>## Event Details</h2>
<p>Sorry, but we do not have any events scheduled at this time.</p>
<p>Please check back later.</p>"
... | true |
a854eed41ad2f6091cfe8f9e62104a1d3d4074a4 | Ruby | mvanholstyn/heroku-autoscale | /lib/heroku/autoscale/base.rb | UTF-8 | 1,182 | 2.5625 | 3 | [] | no_license | require "heroku"
module Heroku
module Autoscale
VERSION = "0.2.2"
class Base
attr_reader :options, :last_scaled
def initialize(options={})
@options = default_options.merge(options)
@last_scaled = Time.now - 60
check_options!
end
def check_options!
er... | true |
8d3fd47994a5a8626f7d34a24cd0d89af6dce479 | Ruby | travismcchesney/aoc-2019 | /day04/p1.rb | UTF-8 | 826 | 3.515625 | 4 | [] | no_license | lower = nil
upper = nil
File.open('input.txt').each do |line|
lower, upper = line.split('-')
end
lower = lower.to_i
upper = upper.to_i
def valid?(password, upper)
parts = password.to_s.split('')
return false if password > upper
increasing = parts[0] <= parts[1] &&
parts[1] <= parts[2] &&
... | true |
518ad522c930b1eef101395f19c598163bdac176 | Ruby | andrewrgoss/udemy-learn-ruby | /06-methods_and_conditionals_ii/case_statement.rb | UTF-8 | 557 | 3.5625 | 4 | [] | no_license | #!/usr/bin/env ruby
def rate_my_food(food)
case food
when 'Steak'
'Pass the steak sauce!'
when 'Sushi'
'Arigato'
when 'Tacos', 'Burritos', 'Quesadillas'
'Cheesy and filling, great combo'
when 'Tofu', 'Brussel Sprouts'
'Healthy'
else
"I don't know about that food"
end
end
puts rate_my... | true |
b7424d9a34a8f1f0d0295bf01b960d88e4f6ccb9 | Ruby | bernardocampos/rps_rcav | /app/controllers/games_controller.rb | UTF-8 | 1,389 | 3.4375 | 3 | [] | no_license | #camel case style of writing
class GamesController < ApplicationController #the reading on classes will teach what's going on here
#you're telling controller to "inherit all the goodies" from ApplicationController class
def play_rock
@computer_move = ["rock","paper","scissors"].sample
# instance variable li... | true |
5862950aa7407e92fa665361c907c235673d61c3 | Ruby | georgewambold/cooking_codex | /app/services/recipe_updater.rb | UTF-8 | 1,455 | 2.65625 | 3 | [] | no_license | class RecipeUpdater
def initialize(args)
@recipe = args[:recipe]
@params = args[:recipe_params]
end
def execute
@recipe.transaction do
@recipe.image = params[:image]
@recipe.title = params[:title]
@recipe.summary = params[:summary]
@recipe... | true |
67fe0c0c3e661c04bf76cfa87c38f5a555b99a5a | Ruby | tyler/distributed_demo | /lib/tcp_socket.rb | UTF-8 | 192 | 2.5625 | 3 | [] | no_license | class TCPSocket
def remote_ip
peeraddr.last.split(':').last
end
def ready_to_read?(timeout=5)
r,_,__ = IO.select([self], nil, nil, timeout)
return r.first == self
end
end
| true |
43bd4ea63f79af603ee91e9b08e761af16b71747 | Ruby | timsully/RB_101_Programming_Foundations | /RB101-RB109 - Small Problems/documentation_again/included_modules.rb | UTF-8 | 195 | 3.453125 | 3 | [] | no_license | =begin
Use irb to run the following code:
Find the documentation for the #min method and change the above code to
print the two smallest values in the Array.
=end
a = [5, 9, 3, 11]
puts a.min(2) | true |
99a9c4d8675f99fa4bc122d4bdce6903a48001aa | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/proverb/f51dffbf65ef4c8b96650d834db64eb1.rb | UTF-8 | 567 | 3.09375 | 3 | [] | no_license | class Proverb
attr_reader :proverb, :options
def initialize(*words)
if words.last.is_a? Hash
@options = words.pop
else
@options = {}
end
@proverb = generate_sequence(*words)
end
def to_s
proverb.to_s
end
private
def generate_sequence(*words)
op = ""
words.each_c... | true |
33cbc6aeae70e90535c288d7790bebd8d206f84e | Ruby | sorah/codily | /lib/codily/root.rb | UTF-8 | 2,347 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'fastly'
require 'codily/elements/service'
module Codily
class Root
class AlreadyDefined < StandardError; end
def initialize(debug: false, service_filter: nil)
@debug = debug
@elements = {}
@service_filter = service_filter
@service_versions = {}
@service_map_name_to_id... | true |
1cbc89fe204226c8a39779f8e5f8cbdfd2355bb0 | Ruby | tanphan313/leet_works | /problems/heap/sort_characters_by_frequency.rb | UTF-8 | 3,009 | 4.28125 | 4 | [] | no_license | <<-Doc
Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.
Return the sorted string. If there are multiple answers, return any of them.
Input: s = "tree"
Output: "eert"
Explanation: 'e' appears twice whil... | true |
8a91470ca13dade2bbfcb99a527701aa3f15675b | Ruby | mjk287/collections_practice_vol_2-prework | /collections_practice.rb | UTF-8 | 1,939 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
# your code goes here
def begins_with_r(array)
array.each do |item|
if item[0] != "r"
return false
end
end
true
end
def contain_a(array)
array.select do |item|
item.include? "a"
end
end
def first_wa(array)
array.each do |item|
string = item.to_s
return item if str... | true |
5e21e2dbcd4c937c19c0f0c0cb983a68d519a1de | Ruby | bnorton/micro_q | /lib/micro_q/statistics/default.rb | UTF-8 | 355 | 2.515625 | 3 | [
"MIT"
] | permissive | module MicroQ
module Statistics
class Default < Base
def initialize
@increment = Hash.new { 0 }
@increment_mutex = Mutex.new
end
def incr(*keys)
@increment_mutex.synchronize do
keys.flatten.each do |key|
@increment[key.to_s] += 1
end
... | true |
db1663de3e503f47f53a952ae31c8af41057fa3a | Ruby | simcap/scrapouille | /test/test_scraping.rb | UTF-8 | 4,643 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'helper'
class TestScraping < MiniTest::Unit::TestCase
def test_scrap_text
scraper = Scrapouille.configure do
scrap 'fullname', at: "//div[@class='player-name']/h1/child::text()"
scrap 'image_url', at: "//div[@id='basic']//img/attribute::src"
scrap 'rank', at: "//div[@class='position'... | true |
4e872f9274445959e28462d20c912693015af1d6 | Ruby | thebravoman/software_engineering_2015 | /c12_trees_before_ast/A_29_Yassen_Alexiev.rb | UTF-8 | 263 | 2.984375 | 3 | [] | no_license | require 'json'
file_contents = File.read('A_29_Yassen_Alexiev.json')
hash = JSON.parse(file_contents)
school = hash['school']
puts "#{school['name']}"
school["classes"].each do |c|
puts " #{c["name"]}"
c["students"].each do |s|
puts " #{s}"
end
end
| true |
f484de9be8bf3434eda1703fe3d0d74ee3006040 | Ruby | pocket7878/bin | /ec2-ssh | UTF-8 | 812 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'json'
env_list_file = File.expand_path("~/.ec2-env.json")
unless FileTest.exists?(env_list_file)
STDERR.puts "Error: ~/.ec2-env.json not exists."
exit(1)
end
if ARGV.count != 3
STDERR.puts "#{__FILE__} allow|deny <env-name> <ip-addr>"
exit(1)
else
command = ARGV[0]
environmen... | true |
1ffdb13cf2dae26f65b074017655ffb4ded1f6c7 | Ruby | swong1267/s0203_exercises | /SerenaWong-swong1267/d2/SerenaWong_greeting.rb | UTF-8 | 320 | 3.75 | 4 | [] | no_license | puts "Please enter your first name: "
first_name = gets.strip
puts "Please enter your middle name: "
middle_name = gets.strip
puts "Please enter your last name: "
last_name = gets.strip
puts "Hello, #{first_name + " " + middle_name + " " + last_name}!"
#better
puts "Hello, #{first_name} #{middle_name} #{last_name}!"
| true |
0597adb1d9c4e48477fc413d7ce59265b80dcb4f | Ruby | railsler/code-examples | /libs/to_boolean.rb | UTF-8 | 160 | 2.78125 | 3 | [] | no_license | module ToBoolean
refine String do
def to_bool
return true if self == true || self.to_s.strip =~ /^(true|yes|y|1|t)$/i
false
end
end
end
| true |
c2b1e77cd5107f8626b685266cb4280c88c7b808 | Ruby | ciax/ciax-xml | /work/xml_a2t.rb | UTF-8 | 734 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
# XML Attribute vs Text Exchanger
require 'optparse'
require 'xml'
include XML
opt = ARGV.getopts('r')
if ARGV.size < 3
abort <<EOF
Usage: a2t (-r) [xpath] [attr] (ns) < xml
//(xpath)@(attr) <-> //xpath.text()
http://ciax.sum.naoj.org/ciax-xml/(ns)
EOF
end
xpath = ARGV.shift
attr = ... | true |
280db110e6c05a36de16c5d354ea68ace7007563 | Ruby | gtempel-mdsol/appraiser | /appraiser.rb | UTF-8 | 1,069 | 2.75 | 3 | [] | no_license |
require_relative './bundlerparser.rb'
require_relative './gemfinder.rb'
require_relative './rubyversioner.rb'
require_relative './bundlerfilter.rb'
parser = BundlerParser.new
gem_finder = GemFinder.new
versioner = RubyVersioner.new
filter = BundlerFilter.new
# you can use either of the Files to test sample bundler o... | true |
d0cc89a4f36ef6662cd308252353a379f5396611 | Ruby | lfrankovich/programming-univbasics-4-array-simple-array-manipulations-part-2-nyc01-seng-ft-060120 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 438 | 3.265625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def using_concat(my_favorite_things, more_favs)
my_favorite_things.concat(more_favs)
end
def using_insert(new_array, another_language)
new_array.insert(4, another_language)
end
def using_uniq(haircuts)
haircuts.uniq
end
def using_flatten(instruments)
instruments.flatten
end
def using_delete(instructors,s... | true |
34501cab25d1b7bbc523b8eb373f8a767c940884 | Ruby | JupiterLikeThePlanet/goby | /lib/Event/NPC/npc.rb | UTF-8 | 622 | 3.359375 | 3 | [
"MIT"
] | permissive | require_relative '../event.rb'
class NPC < Event
# @param [Hash] params the parameters for creating a NPC.
# @option params [String] :name the name.
# @option params [Integer] :mode convenient way for a NPC to have multiple actions.
# @option params [Boolean] :visible whether the NPC can be seen/activated.
... | true |
3e71849c8575d4c013d36bddfdcba3369fb11a49 | Ruby | apaciuk/rails6-api-kickoff | /lib/auth.rb | UTF-8 | 860 | 2.546875 | 3 | [] | no_license | # frozen_string_literal: true
require 'jwt'
class Auth
ALGORITHM = 'HS256'
ACCESS_TOKEN_EXPIRY_DURATION = 30.minutes
REFRESH_TOKEN_EXPIRY_DURATION = 1.day
TOKEN_LEEWAY_DURATION = 10
def self.access_token(payload)
issue(
data: payload,
exp: (Time.zone.now + ACCESS_TOKEN_EXPIRY_DURATION).to_i... | true |
0bbd0919b2541fe9e0caf677df6d17b4428a3c74 | Ruby | crismaproject/wirecloud-widgets | /wirecloud.rb | UTF-8 | 2,721 | 2.609375 | 3 | [] | no_license | require 'mechanize'
require 'nokogiri'
require 'json'
require 'pp'
require 'uri'
class Wirecloud
LOGIN_PATH = '/login'
WORKSPACES_PATH = '/api/workspaces'
RESOURCES_PATH = '/api/resources'
RESOURCE_PATH = '/api/resource/%{vendor}/%{name}/%{version}'
attr_accessor :agent
attr_accessor :base_uri
def init... | true |
91238d1c7dfc61af926425d6c36b329446e61dad | Ruby | stack/advent_of_code_2016 | /15/timing.rb | UTF-8 | 2,460 | 3.46875 | 3 | [] | no_license | #!/usr/bin/env ruby
class Disc #:nodoc:
attr_reader :idx
def initialize(idx, size, position, time)
@idx = idx
@size = size
@position = position
@time = time
@last_known_valid_position = initial_valid
end
def initial_valid
@size - @position - @idx
end
def print(time)
position... | true |
225918a53fc3c8ddf84ebf18d3961f25d7cb0250 | Ruby | hookercookerman/euston | /lib/euston/namespaces.rb | UTF-8 | 935 | 2.640625 | 3 | [] | no_license | module Euston
class Namespaces
def initialize opts = {}
@commands = [opts[:commands]].flatten.compact.uniq
@events = [opts[:events]].flatten.compact.uniq
@message_handlers = [opts[:message_handlers]].flatten.compact.uniq
end
def commands
dereference_string_pointe... | true |
d82d723e4cb0011800b2ee51b000cd7eb0927e28 | Ruby | Dennis-coder/projekt_0 | /models/student.rb | UTF-8 | 1,281 | 2.875 | 3 | [] | no_license | class Student
attr_accessor :id, :name, :image, :group_id
def initialize()
@id = nil
@name = nil
@image = nil
@group_id = nil
end
def add()
SQLQuery.new.add('students', ['name', 'image', 'group_id'], [@name, @image, @group_id]).send
end
def self.get(id... | true |
eb2db879382a0ec33e4311e0e4d101472e669080 | Ruby | KyleChamberlin/ProjectEuler | /src/main/ruby/problem42.rb | UTF-8 | 454 | 3.421875 | 3 | [] | no_license | require 'csv'
triNums = triangleNumbers
answer = 0
words = CSV.parse( open( "data/Problem42.words.txt " ), headers: false )
words[0].each do |word|
if triNums.include?stringSum(word) then
answer += 1
end
end
puts answer
def triangleNumbers
array = Array.new
(1...200).each do |n|
array << (n*(n-1)*0.5).to... | true |
45f7ae69c5fc5f04c17bc4cc2f5df2540f946f69 | Ruby | PeckLiu2017/meta_programming_study | /chapter5/class_definitions/singleton_class.rb | UTF-8 | 276 | 3.34375 | 3 | [] | no_license | class C
def m
m = 1
end
end
singleton_class = class << C
def n
n = 1
end
self
end
puts singleton_class.class
puts singleton_class.superclass
puts singleton_class.instance_methods.join(',')
puts singleton_class.instance_methods(false)
singleton_class.new
| true |
8f8b34e400c0d0b718059c0595483aa69917e30c | Ruby | brady-robinson/ls-rb101 | /small_problems/easy1-9.rb | UTF-8 | 425 | 4.21875 | 4 | [] | no_license | # problem: return the sum of a the digits of a positive integer
# data structure: array
# restrictions: no looping construct allowed
# algorith:
# - define a method that takes a positive integer
# - call the digits method on the integer, then the reduce method
# to add the elements of the resulting array
def sum(int... | true |
814db9642df7db0e9868ceea0198aa58033a6e92 | Ruby | jingen/rubyTuts | /mixins.rb | UTF-8 | 1,216 | 3.40625 | 3 | [] | no_license | # class User
# def initialize username, password
# @username = username
# @password = password
# end
# def login
# end
# def logout
# end
# def sign_up
# end
# end
module Login
def login username, password
if @username == username and @password == password
puts "sucessfully logged in as ... | true |
b2178ed00b25b7de15f1558ce6d14c8c8c9d79af | Ruby | davicitoafc/ruby_fundamentals1 | /exercise3.rb | UTF-8 | 142 | 3.828125 | 4 | [] | no_license | puts "What is your name?"
name = gets
puts "Hi #{name}"
puts "What is your age?"
age = gets.chomp
puts "You were born #{2016 - age.to_i}"
| true |
3f95f871a74202aa4d20cff37592a87b2c4b19b7 | Ruby | 1000Bulbs/gsa | /lib/gsa/readable_results/readable_metatags.rb | UTF-8 | 314 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module GSA
class ReadableMetatags < ReadableResults
def self.parse(metatags)
parse_core(metatags) {|meta_pair| convert(meta_pair) }
end
def self.convert(meta_pair)
{
meta_name: meta_pair[GSA::META_NAME],
meta_value: meta_pair[GSA::META_VALUE]
}
end
end
end
| true |
eb836be50ab1783bcbfac074441f191573dbb19d | Ruby | callum-marshall/oystercard | /lib/oystercard.rb | UTF-8 | 709 | 3.109375 | 3 | [] | no_license | class Oystercard
def initialize
@balance = 0
@journey_list = []
end
attr_reader :balance, :journey_list
def top_up(amount)
@balance += amount
raise "Maximum balance of #{MAX_BALANCE} exceeded" if @balance > MAX_BALANCE
@balance
end
def touch_in(entry_station)
raise 'minimum bala... | true |
2d6d6df7293e8d14cc28c88a6da7eae64802dff2 | Ruby | isisAnchalee/Light-AR | /lib/03_associatable.rb | UTF-8 | 2,805 | 2.890625 | 3 | [] | no_license | require_relative '02_searchable'
require 'active_support/inflector'
# bundle exec rspec spec/03_associatable_spec.rb
# Phase IIIa
class AssocOptions
attr_accessor(
:foreign_key,
:class_name,
:primary_key
)
def model_class
#go from a class name to a class object
@class_name.constantize
en... | true |
7ec823abb5f5c4f0df51492099c303113eda9f4a | Ruby | cocolote/Ruby_Practice | /3rd_c/test-first-ruby/lib/05_silly_blocks.rb | UTF-8 | 174 | 3.203125 | 3 | [] | no_license | def reverser
yield.split.map {|word| word.reverse}.join(' ')
end
def adder(num = 1, &block)
block.call + num
end
def repeater(t = 1,&block)
t.times {block.call}
end
| true |
1d9626979580eb40c48c48439df885536ed6dcb0 | Ruby | sarjumulmi/ttt-with-ai-project-v-000 | /lib/players/computer.rb | UTF-8 | 188 | 2.875 | 3 | [] | no_license | class Players::Computer<Player
def move(board)
position = (1 + rand(9)).to_s
until board.valid_move?(position)
position = (1 + rand(9)).to_s
end
position
end
end
| true |
66ccf19f868b113dec79b889454b65a7c522dd26 | Ruby | balmoral/robe | /lib/robe/common/state/binding.rb | UTF-8 | 7,579 | 3.046875 | 3 | [
"MIT"
] | permissive |
module Robe
module State
# A binding associates a change in a store due to an action
# via a bound callback with a value derived from the store.
class Binding
attr_reader :store, :resolve_block, :values
# Create a Binding to a Robe::State::Store or Robe::State::Atom.
#
... | true |
24c610f60c154eaf86cdcfcd264236911423e84b | Ruby | ajcollins95/connect_four | /lib/board.rb | UTF-8 | 3,131 | 3.453125 | 3 | [] | no_license | class Board
attr_reader :columns
def initialize
@width = 7
@height = 6
@columns = Array.new
(0...@width).each do |i| @columns.push(Column.new(i)) end
end
def check_win(col)
root = last_placed(col)
pointers = root.match_dirs
if pointers.length > 0
connect_4s = 0
pointers.... | true |
d3abb8d4a5f47a55b7a0520ecc8b59ab306b8897 | Ruby | JoeyHilton/Ruby-Sandbox | /fibonacci2.rb | UTF-8 | 616 | 4.03125 | 4 | [] | no_license | puts "Fibonacci of 1000 is:"
start = Time.now
def fibonacci(n)
previous = -1
result = 1
i = 0
while i <= n
sum = result + previous
previous = result
result = sum
i += 1
end
return result
end
puts "Non recursive: #{fibonacci(1000)}"
finish = Time.now
diff = (finish -... | true |
89c46a04d01bfc038af119cfe0865291b676992a | Ruby | Keemotion/alf-core | /spec/unit/alf-predicate/test_predicate.rb | UTF-8 | 2,778 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
shared_examples_for "a predicate" do
let(:x){ 12 }
let(:y){ 13 }
it 'provides a proc for easy evaluation' do
got = subject.to_proc.call(Tuple(x: 12, y: 13))
expect([ TrueClass, FalseClass ]).to include(got.class)
end
it 'can be negated easily' do
expect((!subject)).to be_... | true |
2ee9637bc4c704b4eac3ce8f36495464404e54a1 | Ruby | capicue/url_grey | /lib/url_grey.rb | UTF-8 | 6,624 | 2.671875 | 3 | [] | no_license | require "simpleidn"
require "url_grey/version"
class URLGrey
AUTHORITY_TERMINATORS = "/\\?#"
ABOUT_BLANK_URL = "about:blank"
PATH_PASS_CHARS = "!$&'()*+,/:;=@[]"
PATH_UNESCAPE_CHARS = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"
HOST_ESCAPE_CHARS = " !\"\#$&'()*,<=>@`{|}"
HOST_NORMA... | true |
b105f827ec84303b3866ac78914f69fe41820e9d | Ruby | carlhauck/practice-ruby | /food.rb | UTF-8 | 170 | 2.578125 | 3 | [] | no_license | require "./merch.rb"
require "./sale.rb"
class Food < Merch
include Sale
def initialize(input_hash)
super
@shelf_life = input_hash[shelf_life]
end
end | true |
43f2f34f3a5effdc675f407179c2ca8496829972 | Ruby | jd-erreape/poker_engine | /player.rb | UTF-8 | 205 | 2.921875 | 3 | [] | no_license | require_relative './hand'
class Player
attr_reader :name
attr_accessor :chips, :hand
def initialize(name:, chips: 0, hand: Hand.new)
@name = name
@chips = chips
@hand = hand
end
end | true |
df22f630a98043133641a4ffdab550b7750d1612 | Ruby | felipet1987/a0-webdrone-ruby | /lib/webdrone/vrfy.rb | UTF-8 | 2,044 | 2.765625 | 3 | [
"MIT"
] | permissive | module Webdrone
class Browser
def vrfy
@vrfy ||= Vrfy.new self
end
end
class Vrfy
attr_accessor :a0
def initialize(a0)
@a0 = a0
end
def id(text, attr: nil, eq: nil, contains: nil)
vrfy @a0.find.id(text), attr: attr, eq: eq, contains: contains
end
def css(text,... | true |
72154031519c49bd372d95850228afe605dc63c2 | Ruby | kkirby16/ruby-enumerables-introduction-to-map-and-reduce-lab-seattle-web-120919 | /lib/my_code.rb | UTF-8 | 1,259 | 3.40625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'pp'
require 'pry'
def map_to_negativize(source_array)
negative_array = []
i = 0
while i < source_array.length do
negative_array << source_array[i] * -1
i += 1
end
negative_array
end
def map_to_no_change(source_array)
i = 0
while i < source_array.length do
source_array[i]
i += 1
... | true |
c6ad376ff9cd027099765d4a639af39f363864bb | Ruby | mcspach/lewagon_mx | /batch_443/02_OOP/05_Food-Delivery_Day_One/app/models/meal.rb | UTF-8 | 238 | 2.953125 | 3 | [] | no_license | class Meal
attr_accessor :id
attr_reader :name, :price
def initialize(attrs = {})
@id = attrs[:id] # Data type: Integer
@name = attrs[:name] # Data type: String
@price = attrs[:price] # Data type: Integer
end
end
| true |
f22cd1737180810c95fe31dddd7f362051b1ceee | Ruby | Ball/moirai | /spec/kramdown-extensions/converting_html_extensions_spec.rb | UTF-8 | 2,834 | 2.9375 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'moirai'
describe "normal html output" do
text = <<__TEXT__
# Document
Doing things
__TEXT__
subject(:doc) { Kramdown::Document.new(text, :input => 'Weavable', :auto_ids => false)}
subject(:html_output) { doc.to_html }
it "output html" do
html_output.should eq <<__expected__... | true |
17ea7cea3bd501b5200bc3a5718a8a8681025bea | Ruby | philomory/ld20 | /app/DungeonLayout.rb | UTF-8 | 9,712 | 2.546875 | 3 | [] | no_license | module LD20
class DungeonLayout
attr_reader :dungeon_map, :activated_switches, :boss_room
def initialize
gen_layout
end
def gen_layout
setup
entry
pre_item
item
post_item
magic_key
goal
boss
end
def setup
@stages_pre_item_range ... | true |
08741198b85f78db2042cb9aa5382952a2f40d80 | Ruby | dhgwilliam/omnivore-tweets | /lib/omnivore/cli.rb | UTF-8 | 1,534 | 2.703125 | 3 | [] | no_license | #!/usr/bin/env ruby
$:.unshift('./lib')
require 'omnivore'
require 'slop'
opts = Slop.new do
on '-h', :help, 'Display this documentation' do
puts "Commands implemented so far:"
puts "update - fetch and save any new posts"
puts "posts - display saved post titles"
puts "links - display links fr... | true |
c11ce73c96b91e9d19472a28a14d174675175ee6 | Ruby | sthorpe/bottle_rocket | /lib/time_spanner/time_units/century.rb | UTF-8 | 392 | 2.890625 | 3 | [
"MIT"
] | permissive | module TimeSpanner
module TimeUnits
class Century < CalendarUnit
def initialize
super 2
end
# Overwrite!
def plural_name
:centuries
end
private
def calculate_amount(from, to)
(to.year - from.year) / 100
end
def at_amount
... | true |
386369d0d0e2d074e0f5cd84e03a36f49791edb4 | Ruby | chunlong2012/ThirdPartyService | /ThirdPartyService/app/models/apns_notification.rb | UTF-8 | 1,323 | 2.796875 | 3 | [] | no_license | # 发送的 ios push 的封装对象
class ApnsNotification
attr_accessor :device_token, :alert, :badge, :sound, :other
def initialize(device_token, message)
self.device_token = device_token
if message.is_a?(Hash)
self.alert = message[:alert]
self.badge = message[:badge]
self.sound = message[:sound]
self.other = m... | true |
f56006622c8695d329c3d40c4405bfc493e9c3c0 | Ruby | rayko/amtd | /lib/amtd/client.rb | UTF-8 | 3,148 | 2.546875 | 3 | [
"MIT"
] | permissive | module AMTD
class Client
attr_reader :adapter, :user, :source, :session
def initialize options={}
@user = options.delete(:user) || AMTD.config.user
@source = options.delete(:source) || AMTD.config.source
@password = options.delete(:password) || AMTD.config.password
@adapter = Adapter.... | true |
c0d5f66847b9d0fe863c47d643d48d43f58975d8 | Ruby | kenngo2306/RubyOnRailsProject | /app/models/installer.rb | UTF-8 | 767 | 2.53125 | 3 | [] | no_license | class Installer < ActiveRecord::Base
has_one :user
validates_presence_of :installer_first_name, :installer_phone, :installer_last_name, :installer_email
validates_length_of :installer_first_name, maximum: 50
validates_length_of :installer_last_name, maximum: 50
validates_length_of :installer_email, maximum: ... | true |
2dfda9a420c53ddc1c1379fd00b90b9a2170fe95 | Ruby | gurgeous/scripto | /test/test_file.rb | UTF-8 | 4,760 | 2.578125 | 3 | [
"MIT"
] | permissive | require_relative "helper"
class TestFile < Minitest::Test
include Helper
DIR = "dir".freeze
SRC, DST = "src.txt", "dst.txt"
SRC2, DST2 = "src2.txt", "dst2.txt"
def setup
super
File.write(SRC, "something")
File.write(SRC2, "another thing")
end
#
# basics
#
def test_mkdir
Scripto.... | true |
9ab48ca2937dc7424ffe27967c36a99fc43bcb72 | Ruby | iAmMatthew/guess_the_number | /guess_the_number.rb | UTF-8 | 343 | 3.734375 | 4 | [] | no_license | puts "Welcome to guess the number!"
secret_number = rand(101)
puts "Guess number 0 to 100."
if secret_number < 50
puts "The number is small yafeel."
else
puts "The number is big yafeel."
end
guess = gets.chomp.to_i
until guess == secret_number
puts "Wrong! Try again."
guess = gets.chomp.to_i
end
puts "Co... | true |
df667d90e4e25bee55de5d6340bd4eb5b2f4511e | Ruby | OlegShevtsov1/codebreaker_web_os | /controllers/current_game.rb | UTF-8 | 2,020 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
class CurrentGame
include Helpers::RouteHelper
MINUS = '-'
PLUS = '+'
attr_reader :lose_state, :win_state, :game_over, :decorator
def initialize
@decorator = Helpers::DecoratorHelper.new
end
def reset_game_state
@lose_state = false
@win_state = false
@game... | true |
9dd3e26c832dff67728c0fb20529cfbbd1f3c270 | Ruby | yoichi3223/Ruby | /tenshoku.rb | UTF-8 | 1,108 | 3.671875 | 4 | [] | no_license | # 条件
# 書類選考通過率:5%
# 1次面接通過率:20%
# 2次面接通過率:40%
def tenshoku(number)
# if shorui.include?("1..9")
# shorui = shorui.to_i * 0.01
# else
# shorui = shorui.to_i * 0.1
# end
# if ichiji.include?("1..9")
# ichiji = ichiji.to_i * 0.01
# else
# ichiji = ichiji.to_i * 0.1
# end
# if niji.include... | true |
98f2a7334fb417677a7c769555db8f7e756a5456 | Ruby | joshcass/cryptography | /crypto.rb | UTF-8 | 1,081 | 3.84375 | 4 | [] | no_license |
class Encryptor
def self.run(message, rotation)
letters = ("a".."z").to_a
roto = letters.rotate(rotation)
cipher1 = letters.zip(roto)
caps = ("A".."Z").to_a
caps_roto = caps.rotate(rotation)
cipher2 = caps.zip(caps_roto)
cipher = Hash[cipher1 + cipher2]
message.gsub(/[a-zA-Z]/, ci... | true |
274f402a9a96844a2d5d3d03661d593da4731e6f | Ruby | dowdje/ruby-inheritance-lab-web-0716 | /lib/student.rb | UTF-8 | 177 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative "../lib/user"
class Student < User
attr_reader :knowledge
def initialize
@knowledge = []
end
def learn(nugget)
@knowledge << nugget
end
end | true |
cc4d6b55282ff86d0d25dff87d8cabd17b2c35a3 | Ruby | MrNobad/Spending_Tracker_Project | /db/seeds.rb | UTF-8 | 1,719 | 2.515625 | 3 | [] | no_license | require_relative( "../models/merchants" )
require_relative( "../models/tags" )
require_relative( "../models/transactions" )
require("pry-byebug")
Transaction.delete_all()
Merchant.delete_all()
Tag.delete_all()
merchant1 = Merchant.new({"name" => "Tesco"})
merchant1.save
merchant2 = Merchant.new({"name" => "Lothian T... | true |
4ffceca25b6437d44c1305abb5f23c82f5918f6b | Ruby | k4hun/bc-parkings | /basics/example.rb | UTF-8 | 3,256 | 3.453125 | 3 | [] | no_license | class Article
attr_accessor :likes, :dislikes
attr_reader :title, :body, :author, :created_at
def initialize(title, body, author = nil)
@title = title
@body = body
@author = author
@created_at = Time.now
@likes = 0
@dislikes = 0
end
def like!
@likes += 1
end
def dislike!
... | true |
c4e8660858da59fbe95888adb5d0bbc9efd05648 | Ruby | xeoneux/30-Days-of-Code | /N - Sorting/Solution.rb | UTF-8 | 436 | 3.578125 | 4 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
# Write Your Code Here
i=0
numSwaps=0
while n>i do
j=0
while n-1>j do
if a[j]>a[j+1]
a[j], a[j+1] = a[j+1], a[j]
numSwaps+=1
end
j+=1
end
if numSwaps==0
break
end
... | true |
9f74567f84a53a7b446d7afd5bc4bd7a779aa602 | Ruby | Tubbz-alt/ada-hacking | /testing-puts/hello_world_spec.rb | UTF-8 | 758 | 3.234375 | 3 | [
"MIT"
] | permissive | class HelloWorld
def initialize(output = STDOUT)
@output = output
end
def go!
@output.puts "Hello, world!!!1!!1!!!eleventy!"
end
end
describe HelloWorld do
it "prints 'Hello, World!' to some output stream, using a test double" do
# arrange
output = double('fake IO')
expect(output).to rec... | true |
34377b10496f41dba6646fff1c947febc35e2c18 | Ruby | creaked/ruby_building_blocks | /lib/stock_picker.rb | UTF-8 | 449 | 3.515625 | 4 | [] | no_license | def stock_picker(stock)
buy_date = 0, sell_date = 0, max = 0
i = 0
while i < stock.size do
x = i + 1
while x < stock.size do
if stock[x] - stock[i] > max
buy_date = i
sell_date = x
max = stock[x] - stock[i]
end
... | true |
f17af59a8e3d86f58749687c4f1fe93a61500012 | Ruby | keonjeo/lurado | /test/test_lurado.rb | UTF-8 | 305 | 2.578125 | 3 | [] | no_license | require 'minitest/autorun'
require 'lurado'
class LuradoTest < Minitest::Test
def test_any_hi
assert_equal Lurado.hi, 'hello world'
end
def test_english_hi
assert_equal Lurado.hi, 'hello world'
end
def test_spanish_hi
assert_equal Lurado.hi('spanish'), 'hola mundo'
end
end
| true |
c215bcc74a83b6bbb8705080473e303beddfbfdb | Ruby | esilkartas/meal-planner | /lib/meal_plan/plan.rb | UTF-8 | 1,117 | 3.40625 | 3 | [] | no_license | $LOAD_PATH.unshift File.dirname(__FILE__)
require 'meal_day.rb'
require 'day_amount_error'
module MealPlan
# Main class of meal plan project
class Plan
MAX_DAYS = 30
MIN_DAYS = 1
def initialize(days)
@days = []
self.no_of_days = days
end
def no_of_days
@days.size
end
... | true |
2ca3a1d30236d6da57da591fad99400c576588ba | Ruby | timhabermaas/cubemania | /lib/humanizeable.rb | UTF-8 | 1,116 | 3.1875 | 3 | [] | no_license | module Humanizeable
def humanize (attributes_hash)
attributes_hash.each do |attribute, type|
if type == :time
class_eval <<-ENDEVAL, __FILE__, __LINE__
def human_#{attribute}(options = {})
spacer = options[:spacer] || ""
unit = options[:unit].nil? ? true : options[:... | true |
5c56ae484b65bdc4b0bac58e5aec2d36d9d18dd3 | Ruby | ssciolist/black_thursday | /test/transaction_test.rb | UTF-8 | 2,376 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'test_helper.rb'
require_relative '../lib/transaction.rb'
require_relative '../lib/sales_engine.rb'
require_relative './test_engine.rb'
class TransactionTest < Minitest::Test
def setup
test_engine = TestEngine.new.test_hash
@sales_engine = SalesEngine.new(test_... | true |
81575e6712d0d677c70c05dc993966b17b60ed21 | Ruby | zkayser/freqeigo | /spec/models/word_spec.rb | UTF-8 | 15,496 | 2.671875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Word, type: :model do
context "when calling attributes" do
let(:word) { build :word }
let(:translation) { build :translation, word: word }
it "returns the word attribute" do
expect(word.word).to eq("分かる")
end
it "returns the hiragana attribute... | true |
703c782ab6aa77ea35a6adb095b875a3575f56c4 | Ruby | kim0jun/euler | /002/002.rb | UTF-8 | 263 | 2.921875 | 3 | [] | no_license | currentFibo = 2
previousFibo = 1
temp = 0
sumOfPibo = 0
while currentFibo<4000000 do
sumOfPibo += currentFibo % 2 == 0? currentFibo:0
temp = currentFibo
currentFibo = previousFibo + currentFibo
previousFibo = temp
end
p sumOfPibo # =>4613732
| true |
dde5d93ab8b230edb5ef42b8e44429a01457598f | Ruby | cldwalker/queriac | /spec/models/command_spec.rb | UTF-8 | 4,326 | 2.6875 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../spec_helper'
module CommandSpecHelper
def valid_command_attributes
{
:name => "Google Search",
:keyword => "ggg",
:url => "http://google.com/search?q=(q)"
}
end
end
describe Command do
include CommandSpecHelper
#to get rid of existing... | true |
b95cd9d6ac16fc87f6a84091922f3ca2548ddd52 | Ruby | kineticdata/task-parameter-value-reporter | /lib/main.rb | UTF-8 | 1,836 | 2.703125 | 3 | [] | no_license | require 'java'
require 'csv'
require 'rexml/document'
require 'yaml'
# Require all of the jar files.
Dir[File.expand_path("#{File.dirname(__FILE__)}/../vendor/*.jar")].each do |jar_file|
require jar_file
end
# Require all of the lib files.
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'parameter_value_rep... | true |
59755c5f35cd51ade07a5809bce390f45b2af0f3 | Ruby | alexombre/tests-ruby | /lib/02_calculator.rb | UTF-8 | 270 | 3.53125 | 4 | [] | no_license | def add(a,b)
return (a + b)
end
def subtract(a,b)
return (a - b)
end
def sum(ar)
x = 0
ar.each {|i| x = x + i}
return x
end
def multiply(a,b)
return (a * b)
end
def power(a,b)
return (a**b)
end
def factorial(a)
x = 1
1.upto(a) {|i| x = x * i}
return x
end | true |
b2b0c0ea344f58c91f1df482512d87fecf68639d | Ruby | ZoHerinnot/Jeu_fortnite | /lib/player.rb | UTF-8 | 1,942 | 3.640625 | 4 | [] | no_license | #require "pry"
class Player
attr_accessor :name, :life_points
def initialize(name_player)
@name = name_player
@life_points = 10
end
def show_state
puts "#{@name} a #{@life_points} points de vie "
end
def gets_damage(damage_points)
@life_points -= damage_points
if @life_points <= 0
puts... | true |
7efbd3e2e057f2767639050cce6dac6d0c3ad5cb | Ruby | UbuntuEvangelist/therubyracer | /vendor/cache/ruby/2.5.0/gems/rqrcode_core-0.1.0/lib/rqrcode_core/qrcode/qr_numeric.rb | UTF-8 | 1,035 | 3.28125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module RQRCodeCore
NUMERIC = ['0','1','2','3','4','5','6','7','8','9'].freeze
class QRNumeric
attr_reader :mode
def initialize( data )
@mode = QRMODE[:mode_number]
raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)
... | true |
6955a0c1d23c640e86189ef0e9f8af210f06a2d7 | Ruby | thaysesouza/introduction-to-cs | /name_and_age.rb | UTF-8 | 300 | 4.3125 | 4 | [] | no_license | # name and age
print "Digite seu nome: "
#recebendo uma entrada do teclado
name = gets.chomp
print "Digite sua idade: "
#recebendo uma entrada do teclado
age = gets.to_i()
# saída utilizando puts
# use códigos ruby dentro de uma string com #{code}
puts "Hello, #{name}, você tem #{age} anos!"
| true |
185603883019762ba51dc50fe60227dcdb7cbdcb | Ruby | anastasiaorlova/sinatra-mvc-lab-nyc04-seng-ft-041920 | /models/piglatinizer.rb | UTF-8 | 369 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
attr_reader :string
def translate(str)
phrase = str.split(' ')
phrase.map do |word|
if word.downcase.start_with?(/[aeoui]/)
"#{word}way"
else
idx = word.index(/[aeiou]/)
"#{word[idx, word.size] + word[0, idx]}ay"
... | true |
e45d616e8ee274f97fabf9a81ff76d16c592265a | Ruby | Jaspion/Kilza | /bin/kilza | UTF-8 | 3,969 | 3.140625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'rubygems'
require 'jaspion/kilza'
require 'pastel'
require 'tty'
require 'tty-prompt'
require 'net/http'
require 'uri'
def read_url(url)
Net::HTTP.get(URI.parse(url))
end
module TTY
class Prompt
class List
def enum(value)
@enum = value
end
end
end
end
c... | true |
a03fb4972d097ba8b864aadfc7f2d584f1ffdb92 | Ruby | Aramuad/casino | /person.rb | UTF-8 | 282 | 3.40625 | 3 | [] | no_license | class Person
attr_accessor :bank
attr_reader :name
def initialize
puts "Enter your name:"
@name = gets.strip
puts "What is your initial bankroll?"
@bank = gets.to_f
end
def get_name
return @name
end
def get_bank_roll
return @bank
end
end
| true |
92ccbcc35e25f65577b9237d28d4b873e2fdb564 | Ruby | exarkun451/Blackjack-Webapp | /main.rb | UTF-8 | 4,390 | 3.1875 | 3 | [] | no_license | require 'rubygems'
require 'sinatra'
set :sessions, true
BLACKJACK_AMOUNT = 21
INITIAL_PLAYER_AMOUNT = 500
DEALER_MIN_HIT = 17
helpers do
def calculate_total(cards)
arr = cards.map{|x| x[1]}
total = 0
arr.each do |c|
if c == "Ace"
total +=11
else
total += c.to_i == 0 ? 10 : c.to_i
end
end
... | true |
f1956ddc5a1e48c8778bcb7184cd464c8885b463 | Ruby | eregon/adventofcode | /2022/14a.rb | UTF-8 | 1,010 | 3.109375 | 3 | [] | no_license | require_relative 'lib'
map = {}
source = 500 + 0i
map[source] = '+'
File.readlines('14.txt', chomp: true).each { |line|
line.split(' -> ').each_cons(2) { |a,b|
a = a.split(',').map(&Int).then { _1 + _2.i }
b = b.split(',').map(&Int).then { _1 + _2.i }
dir = (b - a) / (b - a).abs
pos = a
until po... | true |
1f88bf3b178ed76648e035017613210158c8dc49 | Ruby | Nicephora/rubyPreparcoursVendredi | /exo_19.rb | UTF-8 | 104 | 2.765625 | 3 | [] | no_license | mailList = []
i = 0
while i <= 50
if i % 2 == 0
mailList << "jean.dupond.#{i}@email.fr"
end
i += 1
end
puts mailList
| true |
af905485e62711e295751ecfeb0cc91a067f5f0e | Ruby | masaakiKanno850/kadai-ruby-oop-3 | /animal.rb | UTF-8 | 300 | 3.84375 | 4 | [] | no_license | class Animal
attr_accessor :name,:age
def initialize(name,age)
self.name = name
self.age =age
end
def say
puts "#{@name}です。#{@age}歳です。"
end
end
#animal = Animal.new('田中 太郎', 25)
#animal.say | true |
e0f5802e388273a6977fc5e3a62c84d64964988e | Ruby | MASisserson/rb101 | /small_problems/easy_5/11.rb | UTF-8 | 476 | 4.0625 | 4 | [] | no_license | # Spin Me Around in Circles
def spin_me(str)
str.split.each do |word|
word.reverse!
end.join(" ")
end
spin_me("hello world") # "olleh dlrow"
# strings are mutable, and the destructive #reverse is used here.
# I assume that the object will be the same object.
# And I would be wrong. Need to listen to my hunc... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.