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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
70934202a1df810a15077bd1f706943dbc495110 | Ruby | artsy/gris | /lib/gris/middleware/error_handlers.rb | UTF-8 | 1,146 | 2.53125 | 3 | [
"MIT"
] | permissive | module Gris
class Middleware
class ErrorHandlers
def initialize(app)
@app = app
end
def call(env)
response = @app.call env
case response[0]
when 400..500
format_error_response response
else
response
end
rescue RuntimeErro... | true |
cd101247aab5e32a3e7f9ea55d5c4dbae7d4c568 | Ruby | nip3o/7languages | /ruby/2.rb | UTF-8 | 1,133 | 3.515625 | 4 | [] | no_license |
class Tree
attr_accessor :node_name, :children
def initialize(structure)
name, child_structure = structure.first
@node_name = name
@children = child_structure.nil? ? [] : child_structure.map { |e| Tree.new [e] }
end
def visit_all(&block)
visit &block
@children.each { |c| c.visit_all &bloc... | true |
fef96edfc007a482fb7c44044d4d572637162c64 | Ruby | andrewsapa/ruby_small_problems | /easy_4/convert_signed_numbertostring.rb | UTF-8 | 1,769 | 4.3125 | 4 | [] | no_license | ### Convert a Signed Number to a String! ###
# In the previous exercise, you developed a method that converts non-negative
# numbers to strings. In this exercise, you're going to extend that method by
# adding the ability to represent negative numbers as well.
# Write a method that takes an integer, and converts it... | true |
c84d515b1af62b793b469c6c8c5f45b54d5bab65 | Ruby | jamesshieh/algorithms | /hornsat/string_validate.rb | UTF-8 | 121 | 2.703125 | 3 | [] | no_license | # String extention to validate by regexp statement
class String
def validate(regex)
!self[regex].nil?
end
end
| true |
17ca393a8ec3f6b823479e2b988c99fb2f8ff940 | Ruby | Reltre/intro-ruby-workbook_tealeaf | /advanced_questions/quiz_1.rb | UTF-8 | 2,152 | 3.78125 | 4 | [] | no_license | =begin
#1
When n is refernced you should get an error saying that you are referencing an
object that has not been created yet. The if statement will never execute
since it is always false, and this n will never be assigned an initial value.
(^incorrect)
I'm incorrect here, ruby will set the local variable to nil. No u... | true |
eef39b8276cefcbbc57e441f746ffbd6b8e31cde | Ruby | CarouselSMS/VampireAds | /app/models/user.rb | UTF-8 | 1,210 | 2.515625 | 3 | [
"MIT"
] | permissive | class User < ActiveRecord::Base
has_many :messages
# Period after which, users without any activity considered to be expired
EXPIRY_PERIOD = 12.hours
# Unexpired sessions
named_scope :unexpired, :conditions => [ "updated_at > ?", EXPIRY_PERIOD.ago ]
before_create :assign_seq_num
def pp_phone_num
num =... | true |
e99aec3795291a6218478c9dd73c967ee63e7c36 | Ruby | hendrikb/ruby-rectangle-intersection | /rectangle.rb | UTF-8 | 884 | 3.5 | 4 | [] | no_license | require_relative './point.rb'
class Rectangle
attr_reader :top_left, :top_right, :bottom_left, :bottom_right, :name
def initialize name, bottom_left, top_right
@name = name
@bottom_left = bottom_left
@top_right = top_right
@bottom_right = Point.new top_right.x, bottom_left.y
@top_left = Point... | true |
64f68c6336a4b85c861522efb126a7271d486409 | Ruby | GSA/voc_admin | /app/models/reporting_models/choice_question_reporter.rb | UTF-8 | 8,732 | 2.515625 | 3 | [] | no_license | class ChoiceQuestionReporter < QuestionReporter
include ActionView::Helpers::NumberHelper
include Rails.application.routes.url_helpers
field :q_id, type: Integer # ChoiceQuestion id
field :question_text, type: String
# Total number of Answers chosen across ChoiceQuestion responses;
# used for simple av... | true |
bf6c3474db570a46de8facf6406b5cab19472b32 | Ruby | Meggles25/badges-and-schedules-onl01-seng-pt-032320 | /conference_badges.rb | UTF-8 | 753 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
"Hello, my name is #{name}."
end
badge_maker("Arel")
attendees = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def batch_badge_creator(attendees)
badge = []
attendees.each do |attendee|
badge << "Hello, my name is #{attendee}."
end
badge
end
batch_badge_creator(atten... | true |
07957174ebc4328a227bdff74fdf784670c7ff03 | Ruby | steveoro/goggles_admin | /app/strategies/importer_entity_populator.rb | UTF-8 | 9,740 | 2.84375 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'common/format'
=begin
= ImporterEntityPopulator
- Goggles framework vers.: 6.127
- author: Leega
Strategy that populates importer temporary data structures from json parsed data.
Assumes meeting already exist. Also meeting_sessions should exists with meeting_events defined
Note th... | true |
4825b5c6d387c74929fc3f9a7c11dd677b247de5 | Ruby | ruby-rdf/sparql | /lib/sparql/algebra/operator/left_join.rb | UTF-8 | 7,808 | 2.8125 | 3 | [
"Unlicense",
"LicenseRef-scancode-public-domain"
] | permissive | module SPARQL; module Algebra
class Operator
##
# The SPARQL GraphPattern `leftjoin` operator.
#
# [57] OptionalGraphPattern ::= 'OPTIONAL' GroupGraphPattern
#
# @example SPARQL Grammar
# PREFIX : <http://example/>
# SELECT * {
# ?x :p ?v .
# OPTIONAL {
... | true |
1ff5ba2ae9eb2f2028cdbf691a26c8d8813c6277 | Ruby | clairebvs/Battleship | /lib/start.rb | UTF-8 | 952 | 2.796875 | 3 | [] | no_license | class Start
def welcome
"Welcome to BATTLESHIP. Would you like to (p)lay, read the (i)nstructions or (q)uit?"
end
def instructions
'The goal of the game is to sink the ship of your opponent.
Each player calls out one coordinate each turn in attempt to hit one of their opponent’s ships.'
end
de... | true |
9181ee3a344f5f423bf32ca1092304c7a527c9c2 | Ruby | grandnumber/surveyproject | /app/helpers/user_helper.rb | UTF-8 | 377 | 2.59375 | 3 | [] | no_license | helpers do
def debug_hash(label, object)
if object.respond_to? :to_hash
object = JSON.pretty_generate object.to_hash
elsif object.respond_to? :to_a
object = JSON.pretty_generate object.to_a
end
<<-HTML
<div class="debug">
<div class="debug--label">#{ escape_html label }</div>
<pre>#{ es... | true |
b237612d8edead9d0b4b43ee1fca724bf65bb3ad | Ruby | danachen/Ruby | /LS101/easy1/p1.rb | UTF-8 | 197 | 3.59375 | 4 | [] | no_license | # Prob one
def repeat(str, int)
# output = str * int
int.times do
puts str
end
end
repeat('Hello', 3)
# note that using * will output everything on a row
# int.times do puts string
| true |
e031bd47247e8ff8dac8041dc259f0015dec0f00 | Ruby | wribln/pmodbase | /app/models/abbreviation.rb | UTF-8 | 1,209 | 2.6875 | 3 | [] | no_license | require './lib/assets/app_helper.rb'
class Abbreviation < ActiveRecord::Base
include ApplicationModel
include Filterable
before_save :set_sort_code
validates :code,
length: { maximum: MAX_LENGTH_OF_CODE },
presence: true
validates :description,
length: { maximum: MAX_LENGTH_OF_DESCRIPTION },
... | true |
3504900a2a2d117e1b0e3809f586fb13a0278d6d | Ruby | littlekbt/slack-lambda | /bot/lib/slack-lambda-bot/user_file.rb | UTF-8 | 1,995 | 2.640625 | 3 | [] | no_license | class SlackLambdaBot
class UserFile
REGISTER_REGEXP = /name:\s?(.+)\n(language:\s?.*\nversion:\s?.*\n```\n?[\s\S]*\n?```)/
SHOW_REGEXP = />\s*show\s*([a-z|A-Z|0-9|_|-]*)/
LIST_REGEXP = />\s*list/
REMOVE_REGEXP = />\s*remove\s*([a-z|A-Z|0-9|_|-]*)/
RUN_REGEXP = />\s*run\s*([a-z|A-Z|0... | true |
e0f83e6135273d41c6861be228079c2df45b819d | Ruby | praveenag/damsel_in_distress | /app/json_builder.rb | UTF-8 | 276 | 2.546875 | 3 | [] | no_license | require './workspace'
class JsonBuilder
def chart_json(data)
return_val = {}
values = data.collect { |role, value| {'label' => role, 'values' => value} }
return_val['label'] = ["Male", "Female"]
return_val['values'] = values
return_val.to_json
end
end | true |
1809d01093ca2a6325efc028358c07a090de7845 | Ruby | kyoungeagle/phase-0-tracks | /ruby/santa.rb | UTF-8 | 1,828 | 3.5625 | 4 | [] | no_license | class Santa
attr_reader :age
attr_accessor :gender
def initialize(gender, ethnicity)
@gender = gender
@ethnicity = ethnicity
@reindeer_ranking = ["Rudolph", "Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen"]
@age = 0
end
def speak
puts "Ho, ho, ho! Haaaapy Holidays!"
e... | true |
026508e3c415ba64556d10e62958b713fae880d5 | Ruby | arwensookim/aa_classwork | /W5/w5d1/skeleton/lib/p02_hashing.rb | UTF-8 | 640 | 3.53125 | 4 | [] | no_license | class Integer
# Integer#hash already implemented for you
end
class Array
def hash
# [1, 2, 3].hash == [3, 2, 1].hash # => false
hash = 0
self.each_with_index do |el, i|
hash = hash ^ (el.hash & i.hash)
end
hash
end
end
class String
def hash
hash = 0
self.each_char.with_index ... | true |
51042657e84259201ab78006e8955626cff4aab4 | Ruby | dalspok/exercises | /small_problems_i3/easy_7/5.rb | UTF-8 | 308 | 3.34375 | 3 | [] | no_license |
def staggered_case(str)
str.chars.map.with_index {|char, idx| idx.even? ? char.upcase : char.downcase}.join("")
end
p staggered_case('I Love Launch School!') == 'I LoVe lAuNcH ScHoOl!'
p staggered_case('ALL_CAPS') == 'AlL_CaPs'
p staggered_case('ignore 77 the 444 numbers') == 'IgNoRe 77 ThE 444 NuMbErS' | true |
8dd1fa3491f8faf242bb083a73c83b8ad4fa7166 | Ruby | emilyroulund/reverse-each-word-chicago-web-051319 | /reverse_each_word.rb | UTF-8 | 94 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def reverse_each_word (string)
string.split.collect {|word|word.reverse}.join(" ")
end | true |
68bb29d19ef5e18206dae007b93115730582adca | Ruby | jigneshkapuriya/ruby_learning | /if_elsif.rb | UTF-8 | 176 | 3.171875 | 3 | [] | no_license | color = "Yellow"
if color == "Red"
puts "red is rad"
elsif color == "Green"
puts "Green is Great"
elsif color == "Yellow"
puts "yah is Yellow"
else
puts 'hybtfvft'
end
| true |
07de1e338a52be6d05212e2c2c02294bb6479ecb | Ruby | Spekachu/learn_ruby | /08_book_titles/book.rb | UTF-8 | 439 | 3.40625 | 3 | [] | no_license | class Book
def initialize(title=nil)
@title = title
end
def title=(new_title)
little = ['and', 'but', 'or', 'the', 'over', 'a', 'an','in', 'of']
new_title = new_title.split.each do |word|
word.capitalize! unless little.include?(word)
end
new_title[0].cap... | true |
8fce9c8d9f4f28ce4babd3b28501e338115e0846 | Ruby | AnnAllan/assignment_recursion_sprint | /rec.rb | UTF-8 | 1,439 | 4.1875 | 4 | [] | no_license | def factorial_r(n)
if n <= 1
return 1
else
return n * factorial_r(n - 1)
end
end
puts "fact r 5 is #{factorial_r(5)}"
puts "fact r 0 is #{factorial_r(0)}"
def factorial_i(n)
fact = 1
2.upto(n) do |y|
fact *= y
end
return fact
end
puts "fact i 5 is #{factorial_i(5)}"
def sumdigit_r(n)
if... | true |
e4eabc615f55775e1e649972826870a18abd1cf2 | Ruby | Stupot83/battle | /app.rb | UTF-8 | 647 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
require 'sinatra/base'
require './lib/player.rb'
require './lib/game.rb'
require './lib/attack.rb'
class Battle < Sinatra::Application
enable :sessions
set :session_secret, 'session_secret'
get '/' do
erb :index
end
post '/names' do
player_1 = Player.new(name: params[... | true |
bd3cc2e02a020c64e360243813522330485dd93a | Ruby | Nova840/phase-0 | /week-6/nested_data_solution.rb | UTF-8 | 2,080 | 3.734375 | 4 | [
"MIT"
] | permissive | # RELEASE 2: NESTED STRUCTURE GOLF
# Hole 1
# Target element: "FORE"
array = [[1,2], ["inner", ["eagle", "par", ["FORE", "hook"]]]]
# attempts:
# ============================================================
#p array[2][2][3][1]
#p array[2]
#p array[1]
p array[1][1][2][0]
# ==========================================... | true |
a8888fd1d57fbb07402bd13901c37ef4d5936f62 | Ruby | saulocn/curso-ruby | /campo_minado/ponto.rb | UTF-8 | 1,137 | 3.3125 | 3 | [] | no_license | class Ponto
attr_accessor :x, :y, :conteudo, :descoberto, :flag
attr_reader :bomba, :bandeira, :clear, :unknown
def initialize(x, y)
@x = x
@y = y
@descoberto = false
@flag = false
@bomba = "*"
@clear = " "
@unknown = "."
@bandeira = "F"
... | true |
da4feaad352b2ff1dcd5f3d92527fc42efb2b2c5 | Ruby | UjwalBattar/algorithms-dataStructures | /topTal/codility/ruby/cyclic_rotation.rb | UTF-8 | 1,478 | 4.53125 | 5 | [] | no_license | # An array A consisting of N integers is given. Rotation of the array
# means that each element is shifted right by one index, and the last
# element of the array is moved to the first place. For example, the
# rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements
# are shifted right by one index and 6 i... | true |
c6fedc4edd2347e2e7a6f51cc98aeda39e32ed67 | Ruby | cebarks/black_thursday | /lib/merchant_repository.rb | UTF-8 | 548 | 2.625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'repository'
require_relative 'merchant'
class MerchantRepository < Repository
attr_accessor :sorted, :instances
def initialize
@type = Merchant
@attr_whitelist = [:name]
@sorted = false
super
end
def find_all_by_name(fragment)
@instances.sel... | true |
c0950e819c17192ae33ae64d0d7d9c68b1e2ce7c | Ruby | Yobisense/rtesseract | /lib/rtesseract/uzn.rb | UTF-8 | 1,360 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: UTF-8
# RTesseract
class RTesseract
# Alternative approach to Mixed when you want to read from specific areas.
# Requires `-psm 4` which means the text must be "a single column of text of variable sizes".
class Uzn < RTesseract
attr_reader :areas
DEFAULT_ALPHABET = 'Text/Latin'
def initia... | true |
6f6d5f1071d69d5c5294f6d2cba7066dc335f776 | Ruby | AhmedC414/W2D2 | /startup_project/lib/startup.rb | UTF-8 | 1,714 | 3.6875 | 4 | [] | no_license | require "employee"
class Startup
attr_reader :name, :funding, :salaries, :employees
def initialize(name, funding, salaries)
@name = name
@funding = funding
@salaries = salaries
@employees = []
# hash.each do |title, salary|
# @salaries[title] = Employee.new(n... | true |
bc52ca201591f5500ee8516e453f65328fa60c1b | Ruby | temi-adediran/music-library | /lib/models/base_model.rb | UTF-8 | 430 | 2.78125 | 3 | [] | no_license | require_relative '../concerns/findable.rb'
class BaseModel
extend Concerns::Findable
include Concerns::InstanceMethods
attr_accessor :name, :songs
def initialize(name)
@name = name
@songs = []
end
def save
self.class.all << self unless self.class.all.include?(self)
end
def self.destro... | true |
14fdbf55b3d0c990ce68550d655e29135a6aa647 | Ruby | imkaruna/ruby-music-library-cli-v-000 | /lib/music_library_controller.rb | UTF-8 | 1,107 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MusicLibraryController
attr_accessor :path
def initialize(path = './db/mp3s')
MusicImporter.new(path).import
end
def call
puts "Please use these commands: 'list songs', 'list genres', 'list artists', 'play song', 'list artist', 'list genre', 'exit"
exit_musiclibrary = false
while !exit_mu... | true |
512904303b07e29b7ecb256a97d896ce10bf8306 | Ruby | j00p34/inspec | /test/unit/mock/profiles/filter_table/controls/validate_criteria_as_params.rb | UTF-8 | 1,347 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | title '`where` should reject unknown criteria'
raw_data = [
{ id: 1, name: 'Annie', shoe_size: 12},
{ id: 2, name: 'Bobby', shoe_size: 10, favorite_color: 'purple'},
]
control '2943_pass_undeclared_field_in_hash' do
title 'It should tolerate criteria that are keys of the raw data but are not declared as fields'... | true |
9936dbc55649a55df2b5abcf7cf4a9774dce7b1b | Ruby | gsamokovarov/puppet | /lib/puppet/agent/locker.rb | UTF-8 | 1,018 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | require 'puppet/util/pidlock'
# This module is responsible for encapsulating the logic for
# "locking" the puppet agent during a run; in other words,
# keeping track of enough state to answer the question
# "is there a puppet agent currently running?"
#
# The implementation involves writing a lockfile whose content... | true |
a04c03bb94c10160059b9f0dfc141ad119194fcc | Ruby | ronanduddy/exercises | /ruby/pragprog/e4/extent.rb | UTF-8 | 313 | 2.96875 | 3 | [] | no_license | require_relative 'coordinate'
class Extent
def initialize(coordinates)
@coordinates = coordinates
end
def max
@max ||= Coordinate.new(@coordinates.map(&:x).max, @coordinates.map(&:y).max)
end
def min
@min ||= Coordinate.new(@coordinates.map(&:x).min, @coordinates.map(&:y).min)
end
end
| true |
9c662fe64edeea5d7eec84a64898e7b9a90410f8 | Ruby | kaleflatbread/oo-cash-register-nyc-web-051418 | /lib/cash_register.rb | UTF-8 | 871 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :items, :discount, :total, :last_transaction
# initialize a total and items: |array| with an optional discount argument
def initialize(discount=0)
@total = 0
@discount = discount
@items = []
end
# adds an item (with an optional quantity argument) to the total
def ... | true |
a53b1585451d48fcd69fe1d0d4f9799d870e7d6a | Ruby | appfolio/ladle | /lib/ladle/pull_request_info.rb | UTF-8 | 305 | 2.65625 | 3 | [] | no_license | module Ladle
class PullRequestInfo
attr_reader :head_sha, :base_sha
def initialize(head_sha, base_sha)
@head_sha = head_sha
@base_sha = base_sha
end
def ==(other)
@head_sha == other.head_sha &&
@base_sha == other.base_sha
end
alias eql? ==
end
end
| true |
d59453996172e4e3dacf947376a058691393ed39 | Ruby | jamesgraham320/badges-and-schedules-prework | /conference_badges.rb | UTF-8 | 548 | 4.0625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
badge = "Hello, my name is #{name}."
end
def batch_badge_creator(names)
badges = []
names.each do |name|
badges << badge_maker(name)
end
badges
end
def assign_rooms(names)
rooms = []
names.each_with_index {| name, index |
room = index + 1
rooms << "Hello,... | true |
6b68b76ffad7c4f3970190121567ec5278243671 | Ruby | youta777/AtCoder | /ABC/ABC172/a.rb | UTF-8 | 352 | 2.703125 | 3 | [] | no_license | =begin
date:2020.7.17 fri
result:AC
問題URL:https://atcoder.jp/contests/abc172/tasks/abc172_a
結果URL:https://atcoder.jp/contests/abc172/submissions/15276049
=end
# 自分の解答 ------------------------
a = gets.to_i
puts a + a*a + a*a*a
# 他の回答 -------------------------
a = gets.chomp.to_i
puts a + a**2 + a**3 | true |
46560b648210832f737582cd0ed409871b255a68 | Ruby | jomapormentilla/hogwarts-social-network-sinatra | /app/models/concerns/slugifiable.rb | UTF-8 | 361 | 2.875 | 3 | [
"MIT"
] | permissive | module Slugifiable
module ClassMethods
def find_by_slug( slug )
self.all.detect{ |obj| obj.slug == slug }
end
end
module InstanceMethods
def slug
string = self.class == Wizard ? self.username : self.name
string.downcase.gsub(/\W/," ").gsub(/\s+/,"... | true |
35ec88040058aa1d4f8d437ec4264380e9e3593b | Ruby | Yetidancer/backend_module_0_capstone | /day_1/ex11.rb | UTF-8 | 226 | 3.921875 | 4 | [] | no_license | print "How old are you? "
age = gets.chomp
print "How tall are you? "
height = gets.strip
print "How much do you weigh? "
weight = gets.chomp
weight[3..6]="."
puts "So, you're #{age} old, #{height} tall and #{weight} heavy."
| true |
893589366d856da4f0a68157deb3d88b66dc651e | Ruby | danielng09/App-Academy | /w1d2 Classes/io.rb | UTF-8 | 2,014 | 4.125 | 4 | [] | no_license | class NumberGuessingGame
attr_reader :answer
def initialize
@answer = rand(100) + 1
end
def prompt
puts "Guess a number"
Integer(gets)
end
def check(number)
if answer > number
puts "Too Low"
elsif answer < number
puts "Too High"
end
end
def run_game
guess_num =... | true |
b43a86abed739c7a17840e6670994858fc997c91 | Ruby | alxtz/developer-exercise | /exercise.rb | UTF-8 | 772 | 3.984375 | 4 | [] | no_license | class Exercise
def self.marklar(str)
return str.gsub(/\w{5,}/){ |input| /[[:upper:]]/.match(input[0]) ? 'Marklar' : 'marklar' }
end
def self.even_fibonacci(nth)
fib_array = create_fibonacci(nth)
sum = 0
fib_array.each { |x|
if (x%2==0)
sum += x
end
}
# puts('sum... | true |
19a296ad510bbd957b477f0b9334a017851f6867 | Ruby | matthewrudy/moving-people-safely | /app/services/authorize_user_to_access_prisoner.rb | UTF-8 | 646 | 2.625 | 3 | [] | no_license | class AuthorizeUserToAccessPrisoner
def self.call(user, prison_number)
new(user, prison_number).call
end
def initialize(user, prison_number)
@user = user
@prison_number = prison_number
end
def call
return true if user.admin? || user.court? || user.police?
return true unless prisoner_loca... | true |
c17331f2b6d22fefe9395958e9ff53db29c29fed | Ruby | yutingcxiang/blackjack | /spec/deck_spec.rb | UTF-8 | 3,304 | 3.3125 | 3 | [] | no_license | require 'spec_helper'
require_relative '../lib/deck.rb'
require_relative "../lib/card.rb"
RSpec.describe Deck do
let(:new_deck) { Deck.new }
let(:new_deck_suits) { new_deck.cards.map(&:suit) }
let(:new_deck_values) { new_deck.cards.map(&:value) }
context 'when Deck is initialized' do
it 'will have 52 card... | true |
e41051ddb92318300d3072ab0237b95aab3909d6 | Ruby | shubhbjp/josh_app | /app/models/seat.rb | UTF-8 | 1,364 | 2.65625 | 3 | [] | no_license | class Seat < ApplicationRecord
belongs_to :room
has_one :employee
has_many :emp_date_wise_seat, :foreign_key => "seat_id"
scope :get_all_seats_in_room, ->(room_id) { self.where(room_id: room_id).pluck(:id) rescue []}
scope :get_room_wise_seat_count, -> () {self.group(:room_id).count}
def self.room_with_mo... | true |
1cd4bcb7de9a4af6be1ab0530467998b7cf9b0f8 | Ruby | gweng1t/exo_ruby | /voyages.rb | UTF-8 | 621 | 3.140625 | 3 | [] | no_license | villes = ["Paris", "New York", "Berlin", "Montreal"];
voyages = [
{ville: "Paris", duree: 10},
{ville: "New York", duree: 5},
{ville: "Berlin", duree: 2},
{ville: "Montreal", duree: 15}
]
puts "DEFI N°1 - Si j'étais en vacances, j'irais à ..."
villes.each do |ville|
puts ville
end
puts "\n"
puts "DEFI N°2 - Déta... | true |
42e3594fad5f8b62555c0734b4973b8b533f2e59 | Ruby | ecliptik/tcpwrapper-update | /app.rb | UTF-8 | 505 | 2.75 | 3 | [] | no_license | require "sinatra"
require "erb"
#Disable exceptions
disable :show_exceptions
#Update hosts.allow file using erb template
def update_file(ip)
#Template of hosts.allow
template = File.read("hosts.allow.erb")
renderer = ERB.new(template).result(binding)
#Write out file and return success or error
File.write('... | true |
69fd4a7441de8fb6f9716a6b88b2f52538ef729c | Ruby | ennuiiii/cse413-Programming-Languages | /hw7/scan.rb | UTF-8 | 7,715 | 3.640625 | 4 | [] | no_license | # CSE 413
# Assignment # 7
# Qiubai Yu
# 1663777
class Token
attr_reader :kind, :value
def initialize(kind, value = nil)
@kind = kind
@value = value
end
def kind
@kind
end
def value
@value
end
def to_s
# some lexical clas... | true |
1bfa804b40f67f91043c433bece77125c9a49ada | Ruby | michaeltelford/rack_cache | /helpers.rb | UTF-8 | 1,282 | 2.828125 | 3 | [] | no_license |
def html(body, javascript: nil)
<<~HTML
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
#{"<script>#{javascript}</script>" if javascript}
</head>
<body>
#{body}
</body>
</html>
HTML
end
def logi... | true |
0d344e169972ee7202df4bc26359d017989c343c | Ruby | chadellison/exercismio | /word-count/word_count.rb | UTF-8 | 280 | 3.15625 | 3 | [] | no_license | class Phrase
VERSION = 1
def initialize(words)
@words = words.delete(":!!.&@$%^\n").downcase
end
def word_count
word_count = Hash.new(0)
words = @words.gsub(",", " ").scan(/\b[\w']+\b/)
words.each { |word| word_count[word] += 1 }
word_count
end
end
| true |
5db18f4df2796fd1ee1526d8d4ee4a215e08faf5 | Ruby | billylittlefield/ruby-chess | /pieces/steppable.rb | UTF-8 | 413 | 2.6875 | 3 | [] | no_license | module Steppable
def generate_possible_moves(delta_1, delta_2)
possible_moves = []
generate_all_deltas(delta_1, delta_2).each do |deltas|
shifted_pos = pos_with_deltas(pos, deltas)
possible_moves << shifted_pos
end
possible_moves.select do |possible_move|
piece = board[*possible_mov... | true |
b29f4fca4b7600d1d1d4feeabb339f238568087f | Ruby | partyof5/partyof5_playlister | /playlister/lib/models/artist.rb | UTF-8 | 829 | 3.21875 | 3 | [] | no_license | class Artist
attr_accessor :name, :songs
@@artists = []
def initialize
@songs = []
@@artists << self
end
def add_song(song)
self.songs << song
end
def add_song_object_by_name(song_name)
song = Song.new
song.name = song_name
add_song(song)
end
def genres
self.songs.coll... | true |
f20c412cc4ef31288ed4a166229407837cc05b46 | Ruby | Level-turing-team/level_front_end | /app/poros/circle.rb | UTF-8 | 250 | 2.53125 | 3 | [] | no_license | class Circle
attr_reader :profile_picture,
:username,
:id
def initialize(data)
@profile_picture = data[:attributes][:profile_picture]
@username = data[:attributes][:username]
@id = data[:id].to_i
end
end
| true |
0d05dad69cefdc5f13b1f1112786a914a9e8a78d | Ruby | stmichael/spinning_jenny | /spec/spinning_jenny/blueprint_spec.rb | UTF-8 | 811 | 2.796875 | 3 | [] | no_license | require 'spinning_jenny/blueprint'
describe SpinningJenny::Blueprint do
let(:sample_class) { Class.new }
subject { SpinningJenny::Blueprint.new sample_class }
describe "#initialize" do
it "stores the class that the blueprint describes" do
blueprint = SpinningJenny::Blueprint.new(sample_class)
bl... | true |
7576f5196664f25b9c945a70af24af38bfc8712e | Ruby | FlipTech9/ttt-6-position-taken-rb-bootcamp-prep-000 | /lib/position_taken.rb | UTF-8 | 242 | 3.5 | 4 | [] | no_license | # code your #position_taken? method here!
def position_taken? (board, index)
isTaken = nil
if(board[index] == " " || board[index] == "" || board[index] == nil)
isTaken = false
elsif
isTaken = true
end
isTaken
end | true |
3736353b9707e2cb010192a688e730e7c62a4b07 | Ruby | Dujota/reinforcement_tdd_simon | /simon_says.rb | UTF-8 | 361 | 3.578125 | 4 | [] | no_license | def echo(input)
input
end
def shout(input)
input.upcase
end
def repeat(string, multiple)
# prodcuce the desired string and then remove the leading whitespace to make it the test result
(" #{string}" * multiple).lstrip
end
def start_of_word(string, how_many_chars)
string[0..(how_many_chars-1)]
end
def firs... | true |
f62931fc2b2d26381455cf614ce826681c1d7efd | Ruby | rawls/cricket-scoreboard | /lib/cricinfo/structs/team.rb | UTF-8 | 1,153 | 3.03125 | 3 | [] | no_license | module Cricinfo
module Structs
# Represents a cricket team
class Team < Base
attr_reader :id, :name, :short_name, :players
def initialize(opts)
@id = opts[:id]
@name = opts[:name]
@short_name = opts[:short_name]
@players = {}
end
# Con... | true |
a83dd7ed54190764af02d0842218d78bd036fad4 | Ruby | hectorhuertas/headcount | /test/economic_profile_test.rb | UTF-8 | 1,450 | 3.265625 | 3 | [] | no_license | require 'economic_profile'
require 'minitest'
class EconomicProfileTest < Minitest::Test
attr_reader :ep
def setup
data = { name: 'turing',
median_household_income: { [2005, 2009] => 50_000, [2008, 2014] => 60_000 },
children_in_poverty: { 2012 => 0.1845 },
free_or_reduce... | true |
116f112a556d2a5ad65efa903c36a353dac23e14 | Ruby | stade/Saas-code | /hw2/Saas22.rb | UTF-8 | 1,282 | 3.890625 | 4 | [] | no_license | class CartesianProduct
include Enumerable
attr_accessor :cartesian_array
def initialize(firstarr, secondarr)
@cartesian_array = Array.new
if firstarr.count == 0 && secondarr.count == 0
return
elsif
max_index_first = firstarr.count-1
max_index_second = secondarr.count-1
firs... | true |
fab88fe167b60e0a4268134e348a6e8e04f9383c | Ruby | iseitz/Connect-4-Ruby | /lib/board.rb | UTF-8 | 1,936 | 3.734375 | 4 | [] | no_license | require_relative 'game_turn'
require_relative 'board_space'
class Board
LETTERS = ("a".."z").to_a
attr_accessor :game_board
attr_reader :col_num
attr_reader :row_num
attr_reader :letter_to_index
def initialize(col_num = 10, row_num = 10)
@col_num = col_num
@row_num = row_num
@game_board = buil... | true |
920ec33d8a6cd1787c25236d8c4d662daacf210a | Ruby | balthisar/mm_tool | /lib/mm_tool/mm_movie_stream.rb | UTF-8 | 18,255 | 2.859375 | 3 | [
"MIT"
] | permissive | module MmTool
#=============================================================================
# A stream of an MmMovie. Instances contain simple accessors to the data
# made available by ffmpeg, and have knowledge on how to generate useful
# arguments for ffmpeg and mkvpropedit.
#=============================... | true |
06e264c2316406709005e06656beae9017721506 | Ruby | BJSherman80/backend_module_0_capstone | /day_3/exercises/bretts_game.rb | UTF-8 | 1,191 | 3.90625 | 4 | [] | no_license | puts "You walk into a hotel room to find two people standing there. A beautiful
girl in a bikini and a well dressed man in all black holding a suit case."
puts " 1. You go with the girl."
puts " 2. You go with the guy."
print "enter response here> "
input = $stdin.gets.chomp
if input == "1"
puts "1. She asks you if... | true |
bab68785422c6df6ca5437eac8d05d65727a83d3 | Ruby | MattManson/record-shop | /models/artist.rb | UTF-8 | 1,945 | 3.234375 | 3 | [] | no_license | require_relative('../db/sql_runner')
require_relative('./album.rb')
class Artist
attr_reader :id, :name, :logo
def initialize(options)
@id = options['id'].to_i
@name = options['name']
@logo = options['logo']
end
def save
sql = "INSERT INTO artists
( name, logo )
VALUES
( $1, $2)
... | true |
a90fb744076f3b9948e5c53dc6f251e699b0e0ab | Ruby | priit/ubiquo_core | /lib/ubiquo/extensions/filters_helper.rb | UTF-8 | 16,861 | 3 | 3 | [
"MIT"
] | permissive | require 'ostruct'
#= How to include filters on Ubiquo listings
#
#FiltersHelper module provide some commonly used filters. By default, the module is included in <tt>app/helpers/ubiquo_area_helper.rb</tt>:
#
# module UbiquoAreaHelper
# include FiltersHelper
# ...
# end
#
#* The filter itself, containing the HTM... | true |
cc3abed20852d79e37d7c3c4e19e8b1681d190e2 | Ruby | L-rodrigue/6_exo_ruby | /exo_4.rb | UTF-8 | 2,202 | 3.71875 | 4 | [] | no_license | # ## exo 4 - Calcul de la moyenne
# Un instituteur souhaite pouvoir aller plus vite en saisissant
# les notes de ces élèves et en obtenir le nombre est la moyenne pour le trimestre.
# Pour cela, Albert qui a suivi une formation dans l’informatique,
# il y a fort longtemps, lui a proposé de l’aider. Malheureusement,
#... | true |
65b1bf18df2abe20e30b7981ee32e9c86d88cce1 | Ruby | itggot-erik-jergeus/Slutprojekt | /creation-slutprojekt-sinatra/sinatra-skeleton-master/models/activity.rb | UTF-8 | 1,211 | 2.515625 | 3 | [] | no_license | class Activity
include DataMapper::Resource
property :id, Serial
property :title, String, required: true
property :type, String, required: true
property :subject, String
property :planning, String
property :time, Integer
property :date, DateTime, required: true
property :hidden, Boolean, required: tr... | true |
b34d66def8c85d39c1b6b9cb2582163cfdefb08f | Ruby | theghymp/courses | /algo/dijkstra.rb | UTF-8 | 1,330 | 3.21875 | 3 | [] | no_license | # Encoding: utf-8
class DistanceGraph
attr_accessor :vertices
def initialize(filename)
@vertices = {}
File.new(filename).readlines.each do |line|
line = line.chop
line_array = line.split("\t")
vertex = line_array[0].to_i
edges = []
(1..(line_array.size - 1)).each do |i|
... | true |
48007c68aa2f5049f4754e42f3f0b234710f93a7 | Ruby | quarkgluant/rubymonk | /Ruby Primer - Ascent/Handling and Raising - Inline Rescue.rb | UTF-8 | 268 | 2.6875 | 3 | [] | no_license | EXAMPLE_SECRETS = ["het", "keca", "si", nil, "iel"]
def decode(jumble)
secret = jumble.split("").rotate(3).join("")
announce(secret)
secret
end
def decode_all(tab_chaines)
tab_chaines.each{|tab_chaine| decode(tab_chaine)} rescue "it's okay, little buddy."
end | true |
eba854f4919080367d822b9ed30901bf77a02ffb | Ruby | ahnlak-dragonruby/LRtanks | /mygame/app/player.rb | UTF-8 | 2,464 | 3.359375 | 3 | [] | no_license | # player.rb - part of LRTank
#
# Defines the player; knows how to render her and handles all actions
class Player
# Attributes
attr_accessor :player_x, :player_y, :angle
# Some useful constants
PLAYER_WIDTH=9
PLAYER_HEIGHT=9
PLAYER_OFFSET_X=4
PLAYER_OFFSET_Y=4
# Initialisor
def initialize args
... | true |
4971d49cbd0fa23ccc4685bfb7c1b82935177b52 | Ruby | zpixley/Portfolio | /Software Quality Assurance (Ruby)/D4/verifier_test.rb | UTF-8 | 5,847 | 2.671875 | 3 | [] | no_license | require 'simplecov'
SimpleCov.start
require 'set'
require 'minitest/autorun'
require_relative 'block'
require_relative 'wallet'
require_relative 'helper'
# Class VerifierTest contains all the tests to verify functionaility of Verifier.rb
class VerifierTest < Minitest::Test
# Create new instance of the helper class t... | true |
64542295469b2a2b1b080354b0dc71305729bdd3 | Ruby | tijn/virginity | /benchmark/string_benchmark.rb | UTF-8 | 239 | 2.515625 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
# require "#{File.dirname(__FILE__)}/benchmark_helper"
require 'rubygems'
require "memprof"
text = <<end_text
fòó
bär
baß
end_text
Memprof.start
text.each_char { |ch| ch }
puts Memprof.stats
result = Memprof.stop
| true |
927008cf494a342502c84d18a8eb48b6efa2045a | Ruby | ethanhust/devs | /lib/devs/behavior.rb | UTF-8 | 6,392 | 2.984375 | 3 | [
"MIT"
] | permissive | module DEVS
# The {Behavior} mixin provides models with several behavior methods
# in line to the DEVS functions definition (δext, δint, δcon, λ and ta) and
# the DEVS variables (σ, e, t).
# The class must call {#initialize_behavior} during its initialization in
# order to allocate instance variables.
modul... | true |
f91db8988e12309cdc8aecd898d85a719b4a1aff | Ruby | knikadass/array-methods-lab-onl01-seng-pt-070620 | /lib/array_methods.rb | UTF-8 | 529 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_include(array, element)
array.include?(element)
end
def using_sort(array)
famous_dogs = ["wow", "I", "arrays!"]
famous_dogs.sort
end
def using_reverse(array)
famous_dogs = ["wow", "I", "arrays!"]
famous_dogs.reverse
end
def using_first(array)
famous_dogs = ["wow", "I", "arrays!"]
famous_dogs.fir... | true |
9c1f921e754a348efa39a77ce678a38efd43a4dc | Ruby | ehundt/gartenkalender | /app/models/season_old.rb | UTF-8 | 1,282 | 2.609375 | 3 | [] | no_license | class SeasonOld < ApplicationRecord
PHAENOLOG_SEASONS = [ :vorfrühling, :erstfrühling, :vollfrühling,
:frühsommer, :hochsommer, :spätsommer,
:frühherbst, :vollherbst, :spätherbst,
:winter ]
enum season: PHAENOLOG_SEASONS
REGIONS = [ :deutschland ... | true |
707847ad9cf6bafa9fce673ecc13f1647d692cbf | Ruby | niklas/partial_dependencies | /lib/partial_dependencies/graph.rb | UTF-8 | 2,950 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'stringio'
module PartialDependencies
class Graph
def initialize(base_path = File.expand_path(File.join(Rails.root,"app", "views")))
@base_path = base_path
end
def base_path=(base_path)
@base_path = base_path
@views = nil
end
def dot(type = "png", view_set = "u... | true |
175c2245311868dacd5ea7f2168d4b8759dcb7af | Ruby | SmithKirk/takeaway_challenge | /lib/menu.rb | UTF-8 | 537 | 3.859375 | 4 | [] | no_license | class Menu
attr_accessor :dishes
def initialize(dishes)
@dishes = dishes
end
def add_dish(dish, price)
@dishes[dish.to_sym] = price
end
def remove_dish(dish)
raise 'Error: That dish is not on the menu' unless has_dish?(dish)
@dishes.delete(dish.to_sym)
end
def print_menu
@dishe... | true |
378dd4cffc2b59f6943ec4f6921617b16ea1e419 | Ruby | ljonesfl/iprogrammer | /ep7_hw_oop/ruby/oop.rb | UTF-8 | 349 | 3.3125 | 3 | [] | no_license |
class Car
def initialize
puts "Car created."
end
def openAshtray
puts "Ashtray opened."
end
end
class SpyCar < Car
def initialize
puts "SpyCar created."
end
def openAshtray
method(:openAshtray).super_method.call
puts "Ejector seat deployed."
end
end
car = Car.new()
spyCar = SpyCar.new()
car.ope... | true |
9c3773065d8704e61b4c05ff9d16323559081c77 | Ruby | Sambi85/ruby-enumerables-cartoon-collections-lab-part-2-nyc01-seng-ft-060120 | /cartoon_collections.rb | UTF-8 | 487 | 3.3125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
array.collect do |num| num * num end
end
def summon_captain_planet(planeteer_calls)
planeteer_calls.map do |names| "#{names.capitalize}"+"!" end
end
def long_planeteer_calls(planeteer_calls)
planeteer_calls.any? do |string| string.length > 4
end
end
def find_valid_calls(planeteer_cal... | true |
26ec655e9c32d3776dd114a703ed58035e91df69 | Ruby | tenkoma/object-brain | /ch3/3.5/bucho.rb | UTF-8 | 205 | 3.078125 | 3 | [] | no_license | require_relative 'syain'
class Bucho < Syain
def standup
puts '部長がだるそうに起立しました。'
end
def salary
puts "私の給料は#{@basic_salary * 3}円です。"
end
end
| true |
4cbbd56634b8248a12b327ee0d36adae72d8b88c | Ruby | sonialin/launchschool | /Exercises/101-109 Small Problems/Easy 8/08_double_char_pt2.rb | UTF-8 | 400 | 3.5625 | 4 | [] | no_license | def double_consonants(str)
new_str = ""
str.chars.each do |char|
if /[a-zA-Z&&[^aeiouAEIOU]]/.match(char)
new_str << char * 2
else
new_str << char
end
end
new_str
end
puts double_consonants('String') == "SSttrrinngg"
puts double_consonants("Hello-World!") == "HHellllo-WWorrlldd!"
puts d... | true |
71622637f9465d5f0dabb6390dfef5a8feeeb2ca | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/132631b3e8bb4b7ab6c22cfbb837573c.rb | UTF-8 | 439 | 3.609375 | 4 | [] | no_license | require 'prime'
class Raindrops
def convert number
@factors = number.prime_division
return number.to_s unless factors_contain?(3) || factors_contain?(5) || factors_contain?(7)
drops = ""
drops << 'Pling' if factors_contain? 3
drops << 'Plang' if factors_contain? 5
drops << 'Plong' if factors_... | true |
e0c8ac8506fc4049b8507721bf32aec7df91fbce | Ruby | papapabi/project-euler | /29.rb | UTF-8 | 489 | 3.421875 | 3 | [] | no_license | require 'benchmark'
# Finds all distinct terms in the expression a^b given
# inclusive range [a, b] where a and b are both at least 2.
def distinct_terms(a:, b:)
ar = []
(2..a).each do |i|
(2..b).each do |j|
ar << i ** j
end
end
ar.uniq
end
time = Benchmark.measure do
puts 'The cardinality of ... | true |
ba76e8a8fed02cc14a171ec69ad27eb7515bbe6b | Ruby | jayshenk/algorithms | /binary_tree_level_order_traversal.rb | UTF-8 | 721 | 3.859375 | 4 | [] | no_license | # Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
#
# For example:
# Given binary tree [3,9,20,null,null,15,7],
# 3
# / \
# 9 20
# / \
# 15 7
# return its level order traversal as:
# [
# [3],
# [9,20],
# [15,7]
# ]
def lev... | true |
409dd05e7c2d5e853d687091d743bf9043604b57 | Ruby | Aetherus/phantom | /lib/phantom/fork_error.rb | UTF-8 | 214 | 2.5625 | 3 | [
"MIT"
] | permissive | module Phantom
class ForkError < Exception
attr_reader :pid, :pid_file
def initialize(message, pid_file)
super(message)
@pid_file = pid_file
@pid = File.read @pid_file
end
end
end | true |
ccdd6e6df4cbf8de67d731c24ca0d14e288f118a | Ruby | dldinternet/regexp-examples | /lib/regexp-examples/repeaters.rb | UTF-8 | 1,709 | 2.859375 | 3 | [
"MIT"
] | permissive | module RegexpExamples
class BaseRepeater
attr_reader :group
def initialize(group)
@group = group
end
def result(min_repeats, max_repeats)
group_results = @group.result[0 .. RegexpExamples.MaxGroupResults-1]
results = []
min_repeats.upto(max_repeats) do |repeats|
if rep... | true |
de1773195d73987e9dc857566c9674eec3b00e23 | Ruby | samnissen/adomain | /spec/adomain_spec.rb | UTF-8 | 4,767 | 2.53125 | 3 | [
"MIT"
] | permissive | RSpec.describe Adomain do
it "has a version number" do
expect(Adomain::VERSION).not_to be nil
end
describe "#[]" do
context "subdomains the string by default" do
subject { Adomain["http://abc.google.com"] }
it { is_expected.to eq "abc.google.com" }
end
context "domains when no subdom... | true |
9911c66e7d4ca8521c01353cacf9b76266e7e544 | Ruby | JHawk/ruby_euler_solutions | /lib/problem14.rb | UTF-8 | 719 | 3.625 | 4 | [] | no_license | # Find the longest sequence using a starting number under one million.
class Problem14 < Problem
attr_accessor :steps
def initialize
@steps = {}
super
end
def get_steps(start)
return @steps[start] if @steps[start]
if start == 1
return @steps[start] = start
elsif start % 2 ==... | true |
c14bc26b91e49ee6e268a2797873ded1162b9b1d | Ruby | nahiluhmot/readgex | /lib/readgex/simple_parser.rb | UTF-8 | 2,276 | 2.890625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # This module defines the basic parsers used in Readgexes. Note that all of
# these methods are private since they are only supposed to be used in the DSL.
module Readgex::SimpleParser
include Readgex::Motion
private
# Given a character, will try to match the input against that character. Will
# raise a Readgex:... | true |
1eb77352c1a95cdce81e6d0dfebdabb2245eeaf1 | Ruby | Andsbf/robot_exercise | /lib/robot.rb | UTF-8 | 1,344 | 3.640625 | 4 | [] | no_license | require_relative 'custom_exception_classes'
class Robot
attr_accessor :equipped_weapon
attr_reader :items, :health
def initialize
@position = {horizontal:0, vertical:0}
@items = []
@health = 100
@equipped_weapon = nil
end
def position
@position.values
end
def move_left
@posit... | true |
8627b7bbfbd6f61b96c859ae601a79f301522658 | Ruby | danielfone/imaginary-problem | /micro_test.rb | UTF-8 | 1,000 | 3.703125 | 4 | [] | no_license | class MicroTest
ANSI_GREEN = 32
ANSI_RED = 31
def initialize(&test)
@test = test
@pass_count = 0
@fail_count = 0
end
def check(values)
values.each { |input, expected| check_result input, expected }
puts_totals
end
def passed?
@fail_count == 0
end
private
def check_result... | true |
ac84f5f58d1858f66631e70836827d8d899e9f80 | Ruby | taw/ctf-tools | /lib/gf2m_field.rb | UTF-8 | 493 | 3.3125 | 3 | [] | no_license | class GF2mField
attr_reader :poly, :degree
def initialize(poly)
raise "GF(2^m) requires irreducible polynomial" unless poly.is_a?(BinaryPoly)
raise "Polynomial must be irreducible" unless poly.irreducible?
@poly = poly
@degree = poly.degree
end
def ==(other)
other.is_a?(GF2mField) and @pol... | true |
fc6f0615bb86aae09dbc8318c731a0657db428fe | Ruby | jawanng/ttt-with-ai-project-cb-000 | /lib/board.rb | UTF-8 | 765 | 3.984375 | 4 | [] | no_license | require 'pry'
class Board
attr_accessor :cells
def initialize
self.reset!
end
def reset!
@cells = Array.new(9, " ")
end
def display
inside = "-" * 11
puts " #{@cells[0]} | #{@cells[1]} | #{@cells[2]} "
puts inside
puts " #{@cells[3]} | #{@cells[4]} | #{@cells[5]} "
puts insid... | true |
2cb7e1e3da016541bb4c048c3b270800b2884381 | Ruby | JulietDeRozario/THP_Exercices | /Week-3/J3-Sauvegardes/data_saved/lib/mairie_chistmas.rb | UTF-8 | 2,462 | 3.421875 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'rubygems'
class Program
#===> On va récupérer les liens de chaque mairie de chaque commune
def get_townhall_links(doc)
townhall_links = [] #==> Tableau dans lequel je vais stoquer mes liens
doc.css("p > a").each do |link| #==> Je parcours tous les liens ver... | true |
f2a9e1762b741779b92ec1825ff3b0cf5d3d6164 | Ruby | georgebrock/readline-example | /main.rb | UTF-8 | 728 | 3.203125 | 3 | [] | no_license | require "readline"
CHARACTER_NAMES = [
"Arthur Dent",
"Ford Prefect",
"Tricia McMillan",
"Zaphod Beeblebrox",
].freeze
Readline.completer_quote_characters = "\"'"
Readline.completer_word_break_characters = " "
Readline.quoting_detection_proc = proc do |input, index|
index > 0 && input[index - 1] === "\\" &... | true |
7042e5cf5fac7d2f608ece5419993e716d319b34 | Ruby | yuzixun/algorithm_exercise | /main/20170323-89.rb | UTF-8 | 397 | 3.71875 | 4 | [] | no_license | # @param {Integer} n
# @return {Integer[]}
def gray_code(n)
# results = [0]
# n.times do |index|
# puts '-------'
# results += results.reverse.map do |e|
# a = e + 2**index
# puts "#{e.to_s(2)} => #{a.to_s(2)}"
# a
# end
# end
# results
n.times.reduce([0]) { |results, index| resu... | true |
8c348ea00644691e0307f9733188229fd9916923 | Ruby | strider-/AstrosmashClone | /lib/bullet.rb | UTF-8 | 367 | 2.640625 | 3 | [] | no_license | class Bullet
include Collidable
MOVE_STEP = 5
def initialize(window:, start_position:)
super(window: window, image_name: 'bullet.png')
set_position *start_position
end
def update
offset(0, -MOVE_STEP)
end
def draw
image.draw(x, y, 0)
end
def out_o... | true |
078a190e3093d4941409ff66dc282d17c8cfb11c | Ruby | lingdudefeiteng/pipette | /bulk/filter.rb | UTF-8 | 3,759 | 2.515625 | 3 | [] | no_license | #!/usr/bin/env ruby
FILTER_MATCH = File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "fast_filter_matching_vcfs.rb"))
FILTER = File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "filter_vcf.rb"))
ANNOTATE = File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "annotate_vcf.rb")... | true |
f0c79c62d34718eb48389e3d9e65ed55b5e23a10 | Ruby | viniciusoyama/rapidoc | /lib/rapidoc/controller_extractor.rb | UTF-8 | 1,510 | 2.984375 | 3 | [
"MIT"
] | permissive | module Rapidoc
##
# This class open controller file and get all documentation blocks.
# Lets us check if any of this blocks is a `rapidoc` block
# and return it using `json` format.
#
# Rapidoc blocks must:
# - have YAML format
# - begin with `#=begin action` for actions description
# - begin with `#... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.