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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
f14c66941d68b3337a9ccae395589e42083ff215 | Ruby | taiki45/game-of-life | /Settings.rb | UTF-8 | 1,234 | 2.5625 | 3 | [
"MIT"
] | permissive | #Set game Settings
module Settings
#Set how large the game field is
FIELD_SIZE = 30
#Set how many generations game plays
PLAY_TIMES = 100
#Setting for dilay seconds between each generation game displays
DELAY_TIME = 0.1
#set live cells when game starts
#Each consists of row number and colum nu... | true |
5de426309ed24fb06b441e32122faa8c66b0200a | Ruby | nicksolony/programming-univbasics-4-square-array-online-web-prework | /lib/square_array.rb | UTF-8 | 184 | 3.296875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
counter=0
while counter<array.length do
array[counter]=array[counter]**2
counter+=1
end
array
end
numbers=[9,10,16,25]
p square_array(numbers) | true |
67c144ac44a2f831ec32b524c0aba627ceeec56f | Ruby | kbhoffmann/night_writer | /lib/new_night_writer_class.rb | UTF-8 | 1,274 | 3.609375 | 4 | [] | no_license | require 'pry'
# require "./message.txt"
class NightWriter
attr_accessor :message_file
message = File.open(ARGV[0], "r")
message_data = message.read.chomp.split("")
message.close
def initialize
# @message_file = ARGV[0]
# @braille = ARGV[1]
end
# message_data = message.read.chomp.split("")
... | true |
43c8c73479f365a0c60e20061f51584802d1680c | Ruby | ethanbennett/sorters | /bubble_sort.rb | UTF-8 | 309 | 3.03125 | 3 | [] | no_license | class BubbleSort
def sort(letters)
n = letters.size
swapped = true
while swapped == true
swapped = false
(n-1).times do |x|
if letters[x] > letters[x + 1]
letters[x], letters[x + 1] = letters[x + 1], letters[x]
swapped = true
end
end
end
return letters.to_a
end
end | true |
f9947e63f5784ab0de1ebe2a18416bbfe3616747 | Ruby | Christolml/Ruby-udemy | /01_class/06_intro_to_object_method.rb | UTF-8 | 473 | 4.15625 | 4 | [] | no_license |
# devuelve la longitud de mi cadena
p "hello world".length
# convierte a mayusculas mi texto
p "hello world".upcase
# convierte a minisculas mi texto
p "HELLO WORLD".downcase
chris = "que hongo yo soy skra"
p chris.length
p chris.upcase
puts
# me da el siguiente valor de mi numero
p 10.next
p -3.next
puts
# in... | true |
0e2ff62ca417c2879019c4235c71e33690396e25 | Ruby | hannesschaletzky/alternative_bootcamp | /1624189427_difference/solutions/HannahEichelsdoerfer.rb | UTF-8 | 221 | 3.703125 | 4 | [] | no_license | # Please return the elements that are in a but not in b
def difference_check(a, b)
(a-b)
end
# puts difference_check(['Hannah', 'Nate'], ['Hannah'])
# Testing out:
# (a && b).any?
# a.any? { |item| b.include?(item) } | true |
6f30f93ab75c46877c9b4fdca5cfe48f5dd8d6d9 | Ruby | uk-gov-mirror/alphagov.re-rotas | /test/lib/markdown_renderer_test.rb | UTF-8 | 2,543 | 2.796875 | 3 | [] | no_license | require "test_helper"
def assert_same_no_ws(one, other)
assert_equal one.lines.map(&:strip).join(""),
other.lines.map(&:strip).join("")
end
class RotasMarkdownRendererTest < ActiveSupport::TestCase
test "ul" do
markdown = <<~MD
- item
- item
- item
MD
html = Rotas::Mar... | true |
d8a135d093228e5e952a05567ff78c488ccbb406 | Ruby | AceCleric/art_gallery | /spec/test.rb | UTF-8 | 585 | 2.96875 | 3 | [] | no_license | # Returns a User instance that's not saved
user = build(:user)
# Returns a saved User instance
user = create(:user)
# Returns a hash of attributes that can be used to build a User instance
attrs = attributes_for(:user)
# Returns an object with all defined attributes stubbed out
stub = build_stubbed(:user)
# Passing... | true |
9690daf8bec4c96c3f3235f87f73d039c7991f1d | Ruby | RSpace/r2r4examples | /lib/03_prepend.rb | UTF-8 | 1,130 | 3.015625 | 3 | [] | no_license | # Source: http://blog.marc-andre.ca/2013/02/23/ruby-2-by-example/
# Ruby 1.9:
class Range
# From active_support/core_ext/range/include_range.rb
# Extends the default Range#include? to support range comparisons.
def include_with_range?(value)
if value.is_a?(::Range)
# 1...10 includes 1..9 but it does no... | true |
fef2323c219643a0b9f6ba69a9f48651f2a8f8cc | Ruby | mmjosedaniel/learning_ruby | /luky_balance.rb | UTF-8 | 400 | 3.5625 | 4 | [] | no_license | # frozen_string_literal: true
contests = [[13, 1], [10, 1], [9, 1], [8, 1], [13, 1], [12, 1], [18, 1], [13, 1]]
k = 5
arr1 = []
arr2 = []
contests.map { |a| a[1] == 1 ? arr1.push(a[0]) : arr2.push(a[0]) }
arr1.sort!
arr2 += arr1.pop(k) # adding important contests to lose
int1 = arr1.reduce { |sum, a| sum + a }
int2 ... | true |
e451eb03977fd4cf9c4158d53f3f611dec7ad808 | Ruby | GpGardner/Intro_Ruby | /Chapter_1/Arrays/exercise5.rb | UTF-8 | 154 | 2.984375 | 3 | [] | no_license | string = "Welcome to America!"
a = string[6]
puts a
puts ""
#"e"
##e
b = string[11]
puts b
puts ""
#"e"
##A
c = string[19]
puts c
#"error"
##______
| true |
c32ccfd7e1590b07b120eb55866ed76960038569 | Ruby | peterszerzo/sketchup-rubyscript-tutorials | /Behavior-Driven/Vector/features/step_definitions/vector.rb | UTF-8 | 993 | 2.796875 | 3 | [] | no_license | Given /^the vector is (.*) (.*) (.*)$/ do |x, y, z|
@vector = Vector.new(x.to_f, y.to_f, z.to_f)
end
Given /^the other vector is (.*) (.*) (.*)$/ do |x, y, z|
@vector2 = Vector.new(x.to_f, y.to_f, z.to_f)
end
When /^I normalize$/ do
@vector.normalize()
end
When /^I scale by (.*)$/ do |factor|
@vector.scal... | true |
cb02f1b4a189672d9bb1a37a88dc30df37f0dede | Ruby | rosette-proj/rosette-core | /lib/rosette/core/extractor/extractor_config.rb | UTF-8 | 2,490 | 2.75 | 3 | [] | no_license | # encoding: UTF-8
module Rosette
module Core
# Configuration for an extractor.
#
# @example
# ex = ExtractorConfig.new(JsonExtractor::KeyValueExtractor)
# .set_encoding(Encoding::UTF_8)
# .set_conditions do |root|
# root.match_file_extension('.json').and(
# ro... | true |
ca09f1e37d2e09fc990b5e0345f827745c374cf2 | Ruby | bfpepper/credit-check | /test/credit_check_test.rb | UTF-8 | 970 | 2.96875 | 3 | [
"MIT"
] | permissive | require "minitest/autorun"
require "minitest/nyan_cat"
require "./lib/credit_card"
class CreditCardTest < Minitest::Test
def setup
@card_number = "4024007136512380"
@credit_card = CreditCard.new(@card_number)
end
def test_it_can_create_a_class
assert_instance_of CreditCard, @credit_card
end
de... | true |
088c2908e8cea755f50c82716b7f3b95232e18b4 | Ruby | sslaten/Snapchat | /snappie_chattie.rb | UTF-8 | 1,207 | 3.578125 | 4 | [] | no_license | class Snappie_chattie
attr_accessor :password, :points, :best_friends, :streak, :pics, :num_friends
attr_reader :username
def initialize
puts "Please enter a username."
username= gets.chomp
puts "Please enter a password."
password= gets.chomp
puts "Username: #{username} \nPassword: #{pass... | true |
07f39d7c958fad8e9aa4d245b2324fdb8c7daf6f | Ruby | Andsbf/surveyApp | /backend/lib/validator/action/delay.rb | UTF-8 | 441 | 2.6875 | 3 | [] | no_license | module Validator
module Action
class Delay < Base
def valid?
super && hyper_valid?
end
def hyper_valid?
delays_are_numerical? && delay_exists?
end
private
def delay_exists?
delay.values.any? { |interval| interval > 0 }
end
def delays_are_... | true |
46163f36882140b5ad6de3b427ca997fb2798a57 | Ruby | bashosync-labs/riak_json_ruby_client | /test/unit/document_test.rb | UTF-8 | 2,230 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | ## -------------------------------------------------------------------
##
## Copyright (c) "2013" Basho Technologies, Inc.
##
## This file is provided to you under the Apache License,
## Version 2.0 (the "License"); you may not use this file
## except in compliance with the License. You may obtain
## a copy of the L... | true |
a6d5a662b884090fc39bc9014c03228b66d91f83 | Ruby | gitter-badger/Camfed | /lib/sync_exception.rb | UTF-8 | 164 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | class SyncException < Exception
attr_accessor :sync_error
def initialize(sync_error=nil)
self.sync_error = sync_error
super sync_error.to_s
end
end | true |
e1d74819a7c9d049e12579b4746e47375f7cc88b | Ruby | chris-clifton/launch_intro | /morestuff/boolean_regex.rb | UTF-8 | 234 | 3.125 | 3 | [] | no_license | #booelan_regex.rb
def has_a_b?(string)
if /b/.match(string)
puts "We have a match!"
else
puts "We do not have a match."
end
end
has_a_b?("Black Sabbath")
has_a_b?("Judas Priest")
has_a_b?("Pantera")
has_a_b?("Ozzy Osbourne")
| true |
31208d904d747482aca1a00774bccf9c6e80fea8 | Ruby | jjyr/yangscript | /analyzer.rb | UTF-8 | 4,527 | 2.578125 | 3 | [] | no_license | module Yang
class Analyzer
include ParserHelper
attr_reader :global_node
def initialize tree
@global_node = TreeNode.new
@global_node.symbol_table = {}
@tree = tree
end
def analyze
build_symbol_table @tree
end
private
def build_symbol_table node, outer = glo... | true |
3532e0974f078893ec5bf79e0c873c74daf03ad3 | Ruby | showma0734/atcoder_beginner154 | /A.rb | UTF-8 | 1,996 | 3.671875 | 4 | [] | no_license | #問題 => https://atcoder.jp/contests/abc154/tasks/abc154_a
def valid?(s, a, t, b, u)
return false unless [s, t, u].all?{|obj| obj.is_a?(String)}
return false unless [a, b].all?{|obj| obj.is_a?(Integer)}
return false if s == t
return false unless s == u || t == u
_s, _t, _u = s, t, u
return false if [... | true |
c4d2895d2f0a475a3efafcdf2aaafd2c5ff83f22 | Ruby | torafugu/houdd_pre | /app/models/moretinymobtrail.rb | UTF-8 | 1,136 | 2.859375 | 3 | [] | no_license | class Moretinymobtrail < ActiveRecord::Base
belongs_to :moretinymob
has_many :moretinymobbattles
def trailpoints
destX = 0
destY = 0
prevDirection = ""
pointArray = Array.new
pointHash = Hash.new
read_attribute(:trail).split("").each do |direction|
if prevDirection.empty? then p... | true |
e42f2316cf9ebf09ce68b1bdbafa0d05ee5df9a5 | Ruby | jamesascarter/Sudoku-Challenge | /lib/grid_creator.rb | UTF-8 | 617 | 3.078125 | 3 | [] | no_license | module GridCreator
BOX_OF_INDEX = [
0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 2, 2,
3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5, 3, 3, 3, 4, 4, 4, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8, 6, 6, 6, 7, 7, 7, 8, 8, 8, 6, 6, 6, 7, 7, 7, 8, 8, 8
]
def cr... | true |
267b4355dac3a238eb54c2ddd83dbf748eba48ab | Ruby | cielavenir/procon | /yukicoder/tyama_yukicoder644.rb | UTF-8 | 427 | 2.921875 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
M=10**9+7
n,m=gets.split.map &:to_i;r=0;s=[*0..n/m]
(2..n/m).each{|i|s[i]==i&&i.step(n/m,i){|j|s[j]=s[j]/i*~-i};r+=s[i]} # totient
r*=2;(2..n-2).each{|i|r=r*i%M}
p r
__END__
require 'prime'
M=1000000007
def fact(n)
r=1
(2..n).each{|i|r=r*i%M}
r
end
def totient(n)
n.prime_division.reduce(1){|s,e|s*(e... | true |
e5828a3488ff92a32fde82785e108820e0e9bbd8 | Ruby | libin/Off-The-Rails | /rack/print_env.rb | UTF-8 | 184 | 2.78125 | 3 | [] | no_license | require 'pp'
# A simple Rack Middleware that prints the environment
class PrintEnv
def initialize(app)
@app = app
end
def call(env)
pp env
@app.call(env)
end
end
| true |
19ce2b1008a5a6787a19301e60dfe68fa6d19a25 | Ruby | jaruchti/MetaprogrammingRuby | /Chapt4/class_eval.rb | UTF-8 | 294 | 3.875 | 4 | [] | no_license | # Demonstration of using class eval to open a class and define a new method
def add_method_to(a_class)
a_class.class_eval do
def m; 'Hello!'; end
end
end
# Very contrived example of adding new method to String
# using class_eval
add_method_to String
puts "abc".m # => "Hello!"
| true |
1079f700e1fa3e82697602a8568c36c7ebc6bd8f | Ruby | pavelperkin/bitmap_editor | /lib/commands/horizontal_segment.rb | UTF-8 | 1,634 | 2.921875 | 3 | [] | no_license | require_relative '../commands'
require 'dry-validation'
class Commands::HorizontalSegment
def initialize(state:, args: nil)
@state = state.to_a
@x1 = args[0].to_i
@x2 = args[1].to_i
@y = args[2].to_i
@colour = args[3].to_s
validate!
end
def run()
if @x1 >= @x2
(@x2-1 .. @x1-1).... | true |
35402d1b9411e650939931ec3323b45758537863 | Ruby | Neilos/cw_be | /lib/command_parser.rb | UTF-8 | 831 | 3.25 | 3 | [] | no_license | # frozen_string_literal: true
# Parses commands converting them to recognisable BitmapManager
# methods and arguments
class CommandParser
class UnrecognizedError < RuntimeError; end
def parse(full_command)
command_character, *args = full_command.split(' ')
[method_from(command_character), *type_cast_argum... | true |
056dd695250216e67c13d84256aea189ab88ce78 | Ruby | dockhands/CodeCore | /4week/intro_to_ruby/variables.rb | UTF-8 | 177 | 2.625 | 3 | [] | no_license | # > Ruby uses Duck typing
#> no need for const/ let (like in JS)
# cant start with number == have to start with letter
# convention to use snake_case
#e.g. first_name = "dan"
| true |
5831adcc92c6ae10901ce5985cfa95990a3fe78a | Ruby | manuphatak/ruby_recursion | /lib/fibonacci.rb | UTF-8 | 257 | 3.65625 | 4 | [
"MIT"
] | permissive | def fibs(n)
return [] if n === 0
a, b = 1, 1
Enumerator.new do |y|
y << a
(n - 1).times do
y << b
a, b = b, a + b
end
end.to_a
end
def fibs_rec(n, a: 1, b: 1)
return [] if n === 0
[a] + fibs_rec(n-1, a: b, b: a + b)
end | true |
e42ca4e5bf4f371d4305e99ca0ac62a532f7a605 | Ruby | simacektomas/szmgmt | /lib/szmgmt/cli/commands/journal.rb | UTF-8 | 5,599 | 2.71875 | 3 | [
"MIT"
] | permissive | module SZMGMT
module CLI
module Commands
class Journal < Thor
def initialize(*args)
super(*args)
end
def self.command_name
name.split('::').last.downcase
end
def self.usage
"#{command_name} [SUBCOMMAND]"
end
def self.de... | true |
d17c529a989ecfc10aa512699544bd0c7bb6fbff | Ruby | gemvein/social_tokenizer | /features/step_definitions/social_tokenizer_steps.rb | UTF-8 | 916 | 2.890625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | Given /^the String:$/ do |input|
@input = input.to_s
end
When(/^I run the social_tokenizer method$/) do
@output = @input.social_tokenizer
end
Then(/^the result should be a Hash with (\d+) key\-value pairs$/) do |num|
expect(@output).to be_a Hash
expect(@output.count).to be >= num.to_i
end
And(/^each of its k... | true |
3bd747924cd08d0185843b230dcd19accc8db587 | Ruby | divyatalwar/advance_ruby | /dynamic_method_call/bin/main.rb | UTF-8 | 374 | 3.328125 | 3 | [] | no_license | require_relative "../lib/MyClass"
require_relative "../lib/getArgument"
puts "Enter the string"
input_string = gets.chomp
object = MyClass.new(input_string)
puts "Enter method name out of the following to execute :"
puts MyClass.instance_methods(false)
puts "enter method name"
method_name = gets.chomp
arg_object = GetA... | true |
e4b14a82e66bf4c8dfc1923f42d28a8287adedb7 | Ruby | jgarciach/komerko | /app/models/cart.rb | UTF-8 | 1,669 | 2.84375 | 3 | [] | no_license | class Cart < ActiveRecord::Base
attr_accessible :business_id, :user_id
has_many :cart_items
has_many :items, through: :cart_items
belongs_to :user
belongs_to :business
def total
total = 0
self.cart_items.each do |cart_item|
item = cart_item.item
total = total + (item.price*cart_item.q... | true |
ed8e4649b6518f900a98413cacaab597b04b3a82 | Ruby | hulksyed07/Assignment | /factorial.rb | UTF-8 | 122 | 3.5 | 4 | [] | no_license | #Method to find the factorial of a number
def fact(num)
f=1
while num>0
f=f*num
num=num-1
end
puts f
end
fact(4)
| true |
70ca7e937154bb3a1e2840c411f7ee1fd2a31939 | Ruby | ryuichi1208/rb | /src/sample/004.rb | UTF-8 | 598 | 3.96875 | 4 | [
"Apache-2.0"
] | permissive | 2.times do |n|
puts n
end
r = 1..2
r.each { |c|
puts c
}
print("3.times¥n")
3.times{|num|
print("num = ", num, "¥n")
}
print("6.upto(8)¥n")
6.upto(8){|num|
print("num = ", num, "¥n")
}
print("8.downto(6)¥n")
8.downto(6) do |num|
print("num = ", num, "¥n")
end
num = 1
loop{
print("num = ", num, "¥n")
... | true |
caf5875b5068cbc14cc716096709be6a4c250ee6 | Ruby | jioherry/ruby-exercise | /exercise_9.rb | UTF-8 | 698 | 4.125 | 4 | [] | no_license | # @param {Integer[]} prices
# @return {Integer}
# 給定一個包含股票股價變動的陣列,第 i 項的元素代表的是該股票第 i 天的股價。
# 請寫出一個 function 找出你能透過買賣該股票得到的最高利潤。
# 你可以買賣任意次,但不能在同一時間交易多次。(在你下一次買進股票前,你一定要先將股票賣出。)
# max_profit( [1,4,3,6,2] ) should return 6. max_profit( [ 1 ] ) should return 0.
def max_profit(a)
if a.length < 1
puts "0"
end
x = []... | true |
3a4846a6a308831ceb54de1f5ced8244f8e1c621 | Ruby | Pipe12/proyecto_ruby | /proyecto.rb | UTF-8 | 747 | 3.296875 | 3 | [] | no_license | preguntas = Array.new(5) { Hash.new }
preguntas[0] = { pregunta: "1 + 1", resp: 2}
preguntas[1] = { pregunta: "2 + 2", resp: 4}
preguntas[2] = { pregunta: "3 + 3", resp: 6}
preguntas[3] = { pregunta: "4 + 4", resp: 8}
preguntas[4] = { pregunta: "5 + 5", resp: 10}
puts preguntas[0][:pregunta]
puts "BIENVENIDO"
puts ... | true |
adaa5d7729c1ac0416e9c2cde0e0a58abe3b2ec0 | Ruby | mistersourcerer/ruspea | /lib/ruspea/interpreter/form.rb | UTF-8 | 457 | 2.859375 | 3 | [
"MIT"
] | permissive | module Ruspea::Interpreter
class Form
attr_reader :value, :meta
def initialize(value, meta = {closed: true})
@value = value
@meta = meta
end
def eq?(other)
self == other
end
def eql?(other)
self == other
end
def ==(other)
return false if self.class != ... | true |
9a3a916358f3a88059c557981844bafceb2495e9 | Ruby | micapam/policy-calculations-test | /app/models/quote.rb | UTF-8 | 658 | 2.8125 | 3 | [] | no_license | class Quote < ApplicationRecord
validates :age, :trip_duration, presence: true
def price
@price ||= find_price
end
def as_json
hash = super
hash[:age_bracket] = age_bracket = AgeBracket.matching_value age
hash[:trip_duration_bracket] = TripDurationBracket.matching_value trip_duration
hash[... | true |
62d3ca05aa2c31a12adf62808d95aa8c5118a4ba | Ruby | joshua-murphy/thanksgiving_brain_teasers | /strings/split.rb | UTF-8 | 260 | 4 | 4 | [] | no_license | while true
puts "\nGive me a phrase, and I will split the words into an array! \nType 'exit' to leave"
user_input = gets.strip
user_input == "exit" ? exit() : ""
input_arr = user_input.split(" ")
puts input_arr.to_a.to_s
end | true |
a4199883bd63cecc2d194e44a950cc9b92dcdab9 | Ruby | ankostenko/2-year-ruby | /at_exit_practic/second.rb | UTF-8 | 255 | 2.84375 | 3 | [
"Unlicense"
] | permissive | my_core_data = "Original value\n"
at_exit do
puts my_core_data
my_core_data = "Value from first handler\n"
end
at_exit do
puts my_core_data
my_core_data = "Second handler was here\n"
end
print("Var value at app code: ")
print(my_core_data)
| true |
a706034299382bbe3ee099bea76bd6fdd604fe47 | Ruby | SANTOrick/sql-crowdfunding-lab-london-web-career-031119 | /lib/sql_queries.rb | UTF-8 | 1,513 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabetized_by_name
"SELECT title, SUM(amount) FROM projects JOIN pledges ON pledges.project_id = projects.id GROUP BY projects.title"
end
def selects_the_user_name_age_and_pledge_amount_for_all_pledges_alphabetized_by_name
"SELECT name, age, SUM(amount)... | true |
43123a7528de1276b99801df4c50b4ce6a0ac512 | Ruby | twonoo/TwoNoo | /lib/classes/paperclip_image_resizer.rb | UTF-8 | 720 | 2.5625 | 3 | [] | no_license | if ARGV.size == 1
# file name given, so we just resize that one
files = [ARGV[0]]
else
files = Dir[File.dirname(__FILE__) + "/*"].map(&:to_s).map{|x| x[2..-1]}
end
files.each do |filename|
base_name, extension = filename.split('.')
next if extension == 'rb'
`convert #{filename} -resize 300x300^ -grav... | true |
30e0b611e23f6e4e0377e56a52c4cb306e86545c | Ruby | trevor-vaughan/pupmod-simp-common | /lib/puppet/parser/functions/mapval.rb | UTF-8 | 711 | 2.828125 | 3 | [
"LicenseRef-scancode-public-domain",
"Apache-2.0"
] | permissive | module Puppet::Parser::Functions
# This function pulls a mapped value from a text file with the format:
#
# <key> | <value>
#
# The input to the fuction should be (<ruby regex>,<map file>).
#
# Only the last value matched will be returned
newfunction(:mapval, :type => :rvalue, :doc => "Pull a mapped va... | true |
1c54dd1ab22c30a9c9bcfc048748b9ca20c55d4e | Ruby | matos89/ttt-with-ai-project-v-000 | /lib/board.rb | UTF-8 | 1,105 | 3.828125 | 4 | [] | no_license | class Board
attr_accessor :cells
def initialize
self.cells = Array.new(9, " ")
end
def reset!
self.cells = Array.new(9, " ")
end
def display
puts (" #{self.cells[0]} | #{self.cells[1]} | #{self.cells[2]} ")
puts ("-----------")
puts ((" #{self.cells[3]} | #{self.cells[4]} | #{self.ce... | true |
6f1eb25e2ca824624eea9601038b76984e28bfed | Ruby | RichardDenton/ruby-basics | /caesar-cipher.rb | UTF-8 | 647 | 3.9375 | 4 | [] | no_license | def caesar_cipher(text, shift)
encrypted_text = ''
# Iterate through each character
text.each_char do |c|
# If character is alpha shift
if c =~ /[[:alpha:]]/
char_code = c.downcase.ord
shifted_code = (char_code - 97 + shift) % 26 + 97
# Preserve the case of the original charac... | true |
435a6d76e56933f545ca3f73f2ba6c72edd3bcfc | Ruby | resistorsoftware/Modular-Sinatra-with-Warden | /models/user.rb | UTF-8 | 965 | 2.609375 | 3 | [] | no_license | class User < ActiveRecord::Base
include BCrypt
attr_accessible :firstname, :lastname, :email, :password, :active, :admin
validates_uniqueness_of :email, :message => "Email account is already registered."
belongs_to :vendor
def self.authenticate(email, password)
@user = User.where(:email => email)
... | true |
a5b0221fdbd1a7d27fa247fa61800d31549b182f | Ruby | ssnayyar/my_oracle | /chef-repo/ruby_code/inheritance.rb | UTF-8 | 295 | 2.671875 | 3 | [] | no_license | module OracleInc
class Oracle
attr_accessor :oracle_level
def initialize(oracle_level)
@oracle_level = oracle_level
end
end
end
class Weblogic < OracleInc::Oracle
end
weblogicobje = Weblogic.new(10)
oracleobj = OracleInc::Oracle.new(20)
puts weblogicobje.oracle_level
puts oracleobj.oracle_level | true |
5b5d62bbd7a532ef0ca5bd06ff2001ef9a78042b | Ruby | davidtadams/advent-of-code | /2015/3/part2.rb | UTF-8 | 600 | 3.375 | 3 | [] | no_license | # frozen_string_literal: true
directions_chars = { '^' => [0, 1], 'v' => [0, -1], '>' => [1, 0], '<' => [-1, 0] }
both_directions = ARGF.read.chars
.partition
.each_with_index { |_char, index| index.even? }
visited = { [0, 0] => true }
both_directions.each do |directions|
... | true |
e72c4a425b3ea6d09beadc5b4b27372feeff4250 | Ruby | mdelaossa/fitbot | /lib/plugins/insult.rb | UTF-8 | 762 | 2.78125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
class Insult
include Cinch::Plugin
include UtilityFunctions
match /insult(?: (.+))?/i
def execute(m, person)
return unless ignore_nick(m.user.nick).nil?
person ||= m.user.nick
retrys = 2
begin
randomInsult = InsultDB.get(1+rand(InsultDB.count))
m.reply "%s: %s" % [person, ... | true |
5bcb3d912f9d29d7ad4bebd60676a982abc7d958 | Ruby | cecomp64/board-game | /db/seeds.rb | UTF-8 | 5,193 | 2.75 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
b87a65ba374ec7af7baabfea7a7757cf74c11e2b | Ruby | hubertwwong/ruby_test_lab | /postgres/ruby_gem_01/spec/lib/basic_pg_spec.rb | UTF-8 | 782 | 2.84375 | 3 | [] | no_license | require "pry"
require_relative "../support/db"
describe "basic_pg_spec" do
let(:db) {
d = DB.new
d.connect
d.client.drop_table? :items
d.client.create_table(:items) do
primary_key :id
String :name
Float :price
end
return d
}
it "basic insert" do
expect(db.client.... | true |
bc5d00153c491565c149cce9854264fdf542d209 | Ruby | Martsy/backend_prework | /day_3/ex30.rb | UTF-8 | 1,584 | 4.5625 | 5 | [] | no_license | # assigns the amount of people to 30
people = 30
# assigns the amount of cars to 40
cars = 40
# assigns the amount of trucks to 15
trucks = 15
# gives instruction if there are more cars than people
if cars > people
# if the above is true the following string will print
puts "We should take the cars."
# if the first ... | true |
8d4708ded655e669b790127a7b6960b17bdadbe6 | Ruby | rickydo/ruby-review | /super.rb | UTF-8 | 286 | 3.796875 | 4 | [] | no_license | class Foo
def myMethod(s)
puts "parent with " + s
end
end
class Bar < Foo
def myMethod(s)
super
puts "child with " + s
end
end
Bar.new.myMethod('test') #=> parent with test / child with test
# super calls a parent method of the same name with the same arguments
| true |
bdb3a7b3e59a67b8bf2e0751c39d5847d9d62e42 | Ruby | NajibOsman/hair-salon | /spec/stylist_spec.rb | UTF-8 | 2,649 | 2.875 | 3 | [
"MIT"
] | permissive | require('spec_helper')
describe(Stylist) do
describe('.all') do
it('starts off with no stylists') do
expect(Stylist.all).to(eq([]))
end
end
describe('#name') do
it('tells you its name') do
stylist = Stylist.new(name: 'Najib', id: nil)
expect(stylist.name).to(eq('Najib'))
end
... | true |
a200e9af9921860256ad11d55ac3f6caf92ae72f | Ruby | whatupdave/fancymodels | /examples/basic_overview.rb | UTF-8 | 3,983 | 2.828125 | 3 | [] | no_license | require 'fancymodels'
require 'spec'
def clip(str)
str.gsub( str.match(/\n\s+/)[0], "\n" ).strip
end
# these test don't really specifiy the public api, they just exercise the code to keep it heathy
describe "simple store with one model" do
before do
@s = FancyModels.create_store Sequel.sqlite
@s.defin... | true |
f27aef394726d2378000af4e7c5aa4a98de431f7 | Ruby | zachaysan/littlestitious | /test/test_littlestitious.rb | UTF-8 | 5,529 | 2.625 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require 'test_helper'
describe Littlestitious do
before do
suspicious_strings = \
[ "Suspicious CHAR string",
"CHARSuspicious string",
"Suspicious stringCHAR",
"Suspicious string\nCHAR" ]
@zero_width_strings = \
{ :word_joiner=>"",
:mongolian_vowel_separato... | true |
35b5f54616644a1f62745062e1e325369ac7218c | Ruby | JacobGreen920/rottenpotatoes-rails-intro | /app/models/movie.rb | UTF-8 | 223 | 2.609375 | 3 | [] | no_license | class Movie < ActiveRecord::Base
def self.ratings
rs = []
@relation.each { |movie|
if rs.exclude? movie.rating
rs.append(movie.rating)
end
}
return rs.sort
end
end
| true |
b88a77750f440b7c7b7ac031008ad29cfdb99d9c | Ruby | olemanju/RubySelenium | /Cucu/String_1.rb | UTF-8 | 246 | 3.109375 | 3 | [] | no_license | name= "Hello"+"bangalore"
name1='hello' 'mun' 'bangalore'
name2="hello".concat("bangalore")
nam3= "hello"<<"banga"
puts name
puts name1
puts name2
puts nam3
n="ole"
n<<"sing"
n.concat("king")
n.freeze
#n<<"raj"
puts n
| true |
1fef59496c2ce97d5337be035aea20b49b80ac70 | Ruby | amitiitm/SocialNetwork | /tekweld3/app/helpers/application_helper.rb | UTF-8 | 1,553 | 2.90625 | 3 | [] | no_license | # Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def null_to_decimal(numeric_field)
return 0 if numeric_field.nil?
numeric_field.is_a?(String) ? numeric_field.to_d : numeric_field
end
def null_to_integer(numeric_field)
return 0 if numer... | true |
05222292beac406b4749426af9207525f7fbe111 | Ruby | blitline-dev/allq_gem | /lib/allq/connection.rb | UTF-8 | 4,387 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'yaml'
require 'socket'
class AllQ
# Represents a connection to a allq instance.
class Connection
# Default number of retries to send a command to a connection
MAX_RETRIES = 3
# Default retry interval
DEFAULT_RETRY_INTERVAL = 1
# Default port value for beanstalk connection
DEFAUL... | true |
9e1dfce3ae4d4614df6836082cc4e088d322915e | Ruby | ShirishaNagulavancha/ruby_code_katas | /Rspec/error_handling_spec.rb | UTF-8 | 1,201 | 3.265625 | 3 | [] | no_license | require 'rspec'
require_relative '../katas/error_handling'
describe 'handling errors in a predictable way' do
standard_error = Proc.new { raise "A standard error has been raised" }
zero_division_error = Proc.new { |numerator| numerator/0 }
no_method_error = Proc.new { |an_object| an_object.method_call_th... | true |
b6980854f45c78cc91c6d3099b406342c2ef008c | Ruby | eliasm2/problem-solving | /Code Jam/GCJ 2017/GCJ 2017 - Qual. Round/A - Oversized Pancake Flipper/A-large.rb | UTF-8 | 427 | 2.796875 | 3 | [] | no_license | #!/usr/bin/ruby
# encoding: UTF-8
# coding: UTF-8
# -*- coding: UTF-8 -*-
T = gets.chomp.to_i
(1..T).each { |tc|
s, k = gets.split
flips, k = 0, k.to_i
(s.size-1).downto(k-1) do |idx|
if s[idx] == '-'
flips += 1
(idx-k+1..idx).each do |i|
s[i] = s[i] == '+' ? '-' : '+'
end
end... | true |
acb10797f7b0686e0e55da05dfc6e05bd729d422 | Ruby | jtrtj/quantified_self | /spec/services/food_creator_spec.rb | UTF-8 | 874 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
describe FoodCreator do
context 'attributes' do
it 'has a name and calories' do
food_name = Faker::Hipster.word
food_calories = Faker::Number.number(3)
params = { name: food_name, calories: food_calories }
creator = FoodCreator.new(params)
expect(creator.name... | true |
ea04b07558bf02597110aed7687c2fb8ddfacbb5 | Ruby | Tokuhisa1/rack-dynamic-routes-lab-dumbo-web-071618 | /app/application.rb | UTF-8 | 577 | 2.859375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Application
def call env
req = Rack::Request.new env
res = Rack::Response.new
req.path.match(/items/) ? handle_items(req, res) : handle_errors(res)
res.finish
end
def handle_items req, res
item_name = req.path.split("/items/").last # Turn /items/item into item
item = @@items.find ... | true |
3c820943734824d5be5c70f66e18c9bac45fbbf8 | Ruby | victorskurihin/ruby | /stepic.org/Discrete_Math/Dainiak/2.3/Step_6/Step_5_v2_01==02.rb | UTF-8 | 5,185 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
################################################################################
# $Date$
# $Id$
# $Version: 0.1$
# $Revision: 2$
# $Author: Victor |Stalker| Skurikhin <stalker@quake.ru>$
################################################################################
#
clas... | true |
6536b2bf1726b27eeb883384c6c955f4f03db72e | Ruby | rohanphillips/ttt-with-ai-project-online-web-sp-000 | /lib/players/human.rb | UTF-8 | 1,863 | 3.625 | 4 | [] | no_license |
module Players
class Human < Player
def move(board)
board.turn_count
gets.strip
#suspect there's something wrong here
end
end
class Computer < Player
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
... | true |
e8fb5d10876bb17af55570506856a37ef111b1c5 | Ruby | TildeWill/wurl | /config/initializers/httparty/response.rb | UTF-8 | 480 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'httparty'
module HTTParty
class Response < HTTParty::BasicObject
class Headers
def initialize(header = {})
@header = header
end
def to_html(options = {:line_numbers => nil})
headers = []
each_capitalized do |name, value|
headers << "<span style='color... | true |
60def13d84d0da3823b6506d55fda5121d42bff0 | Ruby | semyonovsergey/int-brosayZavod | /lesson 4-1/MyApp6.rb | UTF-8 | 81 | 2.78125 | 3 | [] | no_license | 2.upto(5) do |i|
puts i
10.upto(i) do |i|
puts i
end
#puts "---"
end
| true |
e795d1afab84e6fa64f82ce3a8bb8f8bca9cb84f | Ruby | ba58ajbse/batch_sample | /app/models/chapter5/rank_order_maker.rb | UTF-8 | 804 | 2.765625 | 3 | [] | no_license | module Chapter5
class RankOrderMaker
def each_ranked_user
rank = 1
previous_score = 0
user_sorted_by_score.each do |user|
# 合計スコアが変わった場合は順位を更新
rank += 1 if user.total_score < previous_score
# app/models/ranks_update.rb の create_ranks に書いた
# Rank.create(user_id: ... | true |
7548ef8624c97e8143b884a6b6b1826362150539 | Ruby | zakhi/ruby-aoc | /common/grid.rb | UTF-8 | 370 | 3.625 | 4 | [] | no_license | Point = Struct.new(:x, :y) do
def distance_to(other)
(self.x - other.x).abs + (self.y - other.y).abs
end
def to_s
"<#{x}, #{y}>"
end
end
class Grid
include Enumerable
def initialize(x_range, y_range)
@xs, @ys = x_range, y_range
end
def each(&block)
@xs.each do |x|
@ys.map { |y|... | true |
028e408eca298b74227313db8316c877d833fccb | Ruby | kshamseera/easy-appointment-terminal-app | /main.rb | UTF-8 | 2,351 | 3.015625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'appointment-class'
require_relative 'methods'
appointments = []
start_time = ARGV[0] || 9.0
start_time = start_time.to_i
end_time = ARGV[1] || 17.0
end_time = end_time.to_i
doctor_list = %w[Lucy Peter John Sarah]
load_records(appointments)
def gets
STDIN.gets
end
h... | true |
ee55f427b06ed1167a6f2adac4d37aae457013db | Ruby | aldodelgado/reports_kit | /vendor/bundle/ruby/2.5.0/gems/byebug-2.7.0/lib/byebug/commands/continue.rb | UTF-8 | 940 | 2.609375 | 3 | [
"MIT",
"BSD-2-Clause"
] | permissive | module Byebug
# Implements byebug "continue" command.
class ContinueCommand < Command
self.allow_in_post_mortem = true
self.need_context = false
def regexp
/^\s* c(?:ont(?:inue)?)? (?:\s+(\S+))? \s*$/x
end
def execute
if @match[1] && !@state.context.dead?
filename ... | true |
9c721f4fea839a28f657ade6cf9e3ae06fd1dc59 | Ruby | clyeager/exercises | /small_problems/easy_5/easy_5_11.rb | UTF-8 | 306 | 3.953125 | 4 | [] | no_license | def spin_me(str)
str.split.each do |word|
word.reverse!
end.join(" ")
end
spin_me("hello world") # "olleh dlrow"
#Will the returned string be the same object as argument?
=begin
This method returns a different object, because we call split on the original string, which results in an array.
=end | true |
aaf8129ca0d993ec553e152569c8f82d6bfb68a9 | Ruby | s-take/webcam_test2 | /.bundle/ruby/gems/sinatra-websocketio-0.4.1/sample/bin/cui_chat_client.rb | UTF-8 | 672 | 2.53125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
$:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
require 'eventmachine'
require 'sinatra/websocketio/client'
name = `whoami`.strip || 'shokai'
client = Sinatra::WebSocketIO::Client.new('ws://localhost:9000').connect
client.on :connect do |... | true |
728e6884ab251ac4d88e6b726844dfbd01564a51 | Ruby | looping124/ruby_exos_s2_d1 | /exo_11.rb | UTF-8 | 104 | 3.46875 | 3 | [] | no_license | puts "Bonjour, entre un nombre"
print "> "
x = gets.chomp.to_i
x.times do puts "Salut, ça farte ?"
end | true |
49474920692c3aa2a0a32b1a778365524f3c0a91 | Ruby | akane0915/the-volunteer-tracker | /lib/volunteer.rb | UTF-8 | 1,576 | 2.96875 | 3 | [
"MIT"
] | permissive | class Volunteer
attr_reader(:name, :hours, :project_id, :id)
def initialize(attributes)
@name = attributes.fetch(:name)
@hours = attributes.fetch(:hours)
@project_id = attributes.fetch(:project_id)
@id = attributes.fetch(:id)
end
def ==(another_volunteer)
@name == another_volunteer.name
... | true |
5bcd1ee5210ab7a7c1adae1937f36ba1530af4dc | Ruby | ruckserve/select-my-store | /spec/sms_spec.rb | UTF-8 | 2,582 | 2.90625 | 3 | [] | no_license | require './lib/rps'
describe 'Store' do
it 'exists' do
expects(SMS::Store).to be_a(Class)
end
describe '.initialize' do
it "returns an instance with store attributes" do
store = SMS::Store.new({name: "Chic1", description: "This is a cool store", website: "www.chic1.com", image_url: "/public/images... | true |
1af946a6b83653d16c13722bf5c9bfba7d3798c5 | Ruby | net7/talia_core | /lib/talia_core/data_types/data_loader.rb | UTF-8 | 8,118 | 2.96875 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2010 Net7 SRL, <http://www.netseven.it/>
# This Software is released under the terms of the MIT License
# See LICENSE.TXT for the full text of the license.
module TaliaCore
module DataTypes
# Used for attaching data items by laoding them from files and/or URLs. This will also attempt to
# cr... | true |
590974f401997a1cfc59d5825936fa239a1a03fa | Ruby | kaito0228/apportion | /lib/apportion/setup.rb | UTF-8 | 1,213 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'apportion/util'
module Apportion
# Configure per options
module Setup
module_function
# Determines initial portions for recipients according to optional constraints
#
# @param keys [Hash] correspond to recipients
# @param options [Hash]
# @param options [Hash] :prior_portions from... | true |
44221fc0125e60f4bc9b2059c0de1728b314ff8f | Ruby | eskimosoup/my-project-manager | /app/models/supporting_product_costs_creator.rb | UTF-8 | 965 | 2.890625 | 3 | [] | no_license | class SupportingProductCostsCreator
attr_reader :all_supporting_product_items, :print_job_id
def initialize(print_job_id, all_supporting_product_items)
@print_job_id = print_job_id
@all_supporting_product_items = all_supporting_product_items
end
def grouped_supporting_product_items
all_supporting_... | true |
a633c6efe02e2eec89819cdcbab3b1ff10189dce | Ruby | MichaelSid/Sudoku | /spec/grid_spec.rb | UTF-8 | 1,394 | 3.53125 | 4 | [] | no_license | require './lib/grid.rb'
describe Grid do
context "initialization" do
let(:puzzle) {'015003002000100906270068430490002017501040380003905000900081040860070025037204600'}
let(:grid) {Grid.new(puzzle)}
it "should have 81 cells" do
expect(grid.grid_size).to eq(81)
end
it "should convert the puzzle strin... | true |
fb6160965b79d05ad402f13d7c56b8b2b2ceff49 | Ruby | geewiz/twitch-bot | /lib/twitch/bot/event_handler.rb | UTF-8 | 781 | 2.953125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Twitch
module Bot
# Handles a message of a specific type
class EventHandler
attr_reader :event, :client
#
# Return a list of event types this handler subscribes to
#
# @return [Array] list of event types
#
def self.handled_events... | true |
12957663e9c26be327e321bba29dd12ae9c08b80 | Ruby | beet/joplin_alfred_actions | /lib/joplin/base.rb | UTF-8 | 925 | 2.703125 | 3 | [] | no_license | =begin
Template class for interacting with Joplin files.
Concrete classes must implement a #alfred_items abstract method that returns
an array of Alfred::Item instances.
Provides the #for_each_note block method that iterates through all Joplin
note files and yields a Joplin::NoteFile instance.
=end
module Joplin
... | true |
101e713278d8486072a57126c451a969d1c114d9 | Ruby | faker-ruby/faker | /test/faker/default/test_faker_code.rb | UTF-8 | 1,514 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../../test_helper'
class TestFakerCode < Test::Unit::TestCase
def setup
@tester = Faker::Code
end
def test_npi_regexp
assert_match(/[0-9]{10}/, @tester.npi)
end
def test_deterministic_npi
Faker::Config.random = Random.new(42)
v = @tester.npi
... | true |
0e735a23ef78f6d887de7d17bd2c3b4a1f439937 | Ruby | cableray/soggle | /spec/soggle/board_spec.rb | UTF-8 | 4,603 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Soggle::Board do
describe "initializing" do
context "when board is empty" do
context "when board is string" do
board=""
it "should raise exception" do
expect{Soggle::Board.new board}.to raise_error ArgumentError
end
end
context "w... | true |
4db9605ed63defea00f2851e0336534b54099665 | Ruby | raquelstalcup/URL-shortener | /bottles2.rb | UTF-8 | 698 | 3.671875 | 4 | [] | no_license | num = 99
100.times do
if num > 2
puts "#{num} bottles of beer on the wall"
puts "#{num} bottles of beer"
puts "take one down and pass it around"
num = num - 1
puts "#{num} bottles of beer on the wall"
puts " "
elsif num == 2
puts "2 bottles of beer on the wall, 2 bottles of beer"
puts "take one down an... | true |
e1a2ed747d449e5b7b2b70008b866ead066ac378 | Ruby | davidfebca/IronHack | /WeekTwo/DayTwo/user_validator/lib/user.rb | UTF-8 | 299 | 2.515625 | 3 | [] | no_license | require 'io/console'
require 'yaml/store'
class User
attr_accessor :id,:username,:password,:loged
def initialize id, username, password
@id = id
@username = username
@password = password
@loged = false
end
def login
@loged = true
end
def loged
@loged
end
end
| true |
fc37adb75839d2303f0d9ed1a11cbb3a1237acfe | Ruby | cpkenn09y/CodingAlgorithms | /ci/IA6N/challenge_1/c1.rb | UTF-8 | 918 | 3.5 | 4 | [] | no_license | require 'pry'
# @param {Integer} rows
# @param {Integer} column
# @param {Integer[]} grid
# @return {Integer}
def numberAmazonTreasureTrucks(rows, column, grid)
def helper(grid,row,col,counter)
x = 0
y = 0
new_grid = []
at_park = false
last_identified_park_x = nil
last_identified_park... | true |
ed9fbbb63cbc5cee9c2f627d4966e9eec15587fd | Ruby | MastersAcademy/ruby-course-2018 | /objects/taras.turchenko/task_2.rb | UTF-8 | 1,355 | 3.234375 | 3 | [] | no_license | require_relative './mario_game'
class MarioGame
def self.add_final_screen
last_instance = ObjectSpace.each_object(self).to_a.first
last_instance.instance_eval do
def show_final_screen
"My congratulations! It's end of the game"
end
end
end
end
mario1 = MarioGame.new('Overworld', 21,... | true |
3041377821039af4b9d66c644beca5c099f8f71d | Ruby | kzapata19/tic-tac-toe | /lib/validation.rb | UTF-8 | 432 | 3.390625 | 3 | [] | no_license | #purpose of this module is to verify that input is an integer within 1-9 range else continue to prompt until input is valid
module Validation
def self.handle_player_input(error_msg, action,player_input)
if !valid_player_input?(player_input)
error_msg
action
else
player_input
end
end
... | true |
ce43bace3715290c99f57dc171837c268cf0c40c | Ruby | Fujita-Hiroki/myapp | /spec/models/user_spec.rb | UTF-8 | 3,286 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
let(:user) { create(:user) }
describe "User" do
it "should be valid" do
expect(user).to be_valid
end
end
describe "name" do
it "should be present" do
user.name = " "
expect(user).to be_invalid
end
context "50... | true |
08976a45a2848aa4cf496762b08b25b21739b69a | Ruby | tlball/tball_leepfrog | /run_me.rb | UTF-8 | 788 | 2.734375 | 3 | [] | no_license | require './navlinks/'
navlinks = Navlinks.new
puts ""
puts "Coding Exercise by Tricia Ball 6/8/2016"
puts ""
puts "Here are my results from this coding exercise."
puts "This output should match that of the sample data, with the exception of the title and class attributes do not exist"
puts "Those could be added in by... | true |
19dcccd758c337600b8847198c54c66c234f606b | Ruby | softprops/nuwords | /lib/nuwords.rb | UTF-8 | 5,652 | 3.6875 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #
# A Simple library for converting numeric values into words. Supports values
# up to #MAX (999,999,999,999,999). I could support more but it's not really that useful at
# that point. I draw the line at
# 'nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million
# nine hun... | true |
59d5c6e6d91909abfa3d53e4870af0f100131b96 | Ruby | Mirrior/code_exercises | /ruby_exercises/week1/offDay/fizzbuzz.rb | UTF-8 | 263 | 3.328125 | 3 | [] | no_license | @x = 1
until @x > 100
if @x.modulo(3).zero? && @x.modulo(5).zero?
print "fizzbuzz "
@x += 1
elsif @x.modulo(3).zero?
print "fizz "
@x += 1
elsif @x.modulo(5).zero?
print "buzz "
@x += 1
else
print "#{@x} "
@x += 1
end
end | true |
22e357a201a1eb1a7bdb336531356cd3bb9a954e | Ruby | leonthemisfit/SudokuBoard | /lib/board_validate.rb | UTF-8 | 1,041 | 2.8125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'errors'
module Sudoku
module BoardValidate
# rubocop:disable Metrics/MethodLength
def group_valid?(indx, type = :row)
values =
case type
when :row
row(indx)
when :column
column(indx)
when :grid
... | true |
87f1d9a0e5cb8b70d6a70c57e2939ef4e9e73a17 | Ruby | kclowes/sinatra_practice | /lib/item_repository.rb | UTF-8 | 348 | 3.15625 | 3 | [
"MIT"
] | permissive | class ItemRepository
attr_reader :item_list
def initialize
@item_list = [ Item.new("Cuppa Joe", 1), Item.new("Cup of Tea", 2), Item.new("Cup of Pizza", 3) ]
@count = 4
end
def add_items(item_to_add=nil)
if item_to_add != nil
@item_list << Item.new(item_to_add, @count)
@count += 1
e... | true |
6fc09fd446460909f8caba38cec3c4cfc13db81c | Ruby | zlschatz/phase-0 | /week-5/gps2_2.rb | UTF-8 | 4,646 | 4.1875 | 4 | [
"MIT"
] | permissive | #GPS 2.2 Challenge
# PSEUDOCODE:
# -----------
# What is your main goal / task?
# What methods do you need for this?
# Do you need to initialize any variables or contianers for your methods to use?
# (Outside of the methods)
# Then for each method...
# 1. What is the expected input?
# 2. What is the expected outp... | true |
2292b6d0c1dfde273d1cb7d42310f6bf77de183d | Ruby | StephanieRuthJones/dog-park-ruby-practice | /environment.rb | UTF-8 | 426 | 2.875 | 3 | [] | no_license |
require_relative './owner'
require_relative './pet'
require_relative './dog_park'
require 'pry'
damon = Owner.new('Damon', 25)
andrew = Owner.new('Andrew', 20)
gage = Owner.new('Gage', 22)
arena = Owner.new('Arena', 19)
spot = Pet.new('spot', 'poodle')
ted = Pet.new('ted', 'spaniel')
dogpark1 = DogPark.new(spot, d... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.