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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
cd6eb12ec95f0b1695ca5e868453f72b7dbad1e8 | Ruby | melanierogan/Mel_at_Makers | /ruby_times/airporttimes.rb | UTF-8 | 1,258 | 3.84375 | 4 | [] | no_license | class Airport
attr_reader :airport
# can make a new person with a name, when you intialise something you put an @ next to it
def initialise (airport)
@airport = airport
end
end
class Plane
attr_reader :airport
def initialize (plane, airport, weather)
@plane = plane
@a... | true |
56f102eeda203b1727023cf1b37ae7b1fd576e13 | Ruby | lwoodson/todo | /spec/lib/todo/item_renderer_spec.rb | UTF-8 | 3,815 | 3.046875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'stringio'
describe Todo::ItemRenderer do
before do
@renderer = Todo::ItemRenderer.new(test_stream)
end
describe "#render_output" do
context "when passed nil" do
it "should render nothing when passed a nil value" do
@renderer.render_output(nil)
stream_... | true |
28e077e07d7150824eb1a53c8680a3e750270676 | Ruby | alisong779/key-for-min-value-online-web-prework | /key_for_min.rb | UTF-8 | 241 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # prereqs: iterators, hashes, conditional logic
# Given a hash with numeric values, return the key for the smallest value
def key_for_min_value(name_hash)
if x = name_hash.sort_by {|key, value| value}.first
x[0]
else x
end
end
| true |
bee0607ad9da5ece5fe435273324b87a08a21ac2 | Ruby | proyectoFilas/simulacionFilas | /CashRegister.rb | UTF-8 | 520 | 3.015625 | 3 | [] | no_license | load 'Client.rb'
class CashRegister
def initialize
@available = true
end
attr_reader :client
attr_accessor :available
def serviceTime
random = Random.new
random.rand(4..25)
end
def customerArrives client, tArrive
@client = client
@available = false
@arrivalTime = tArrive
@... | true |
c8e39fbc85f623946a82c16badae67aefcf45b66 | Ruby | darkcode357/thg-framework | /lib/thg/core/Mods/exploit/sqli/common.rb | UTF-8 | 4,518 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'msf/core/module/ui'
module Msf::Exploit::SQLi
class Common
include Msf::Module::UI
#
# Creates an instance of an SQL Injection object, users should use the create_dbms method of Msf::Exploit::SQLi instead
#
# @param datastore [DataStore]
# @param framework [Framework]
# ... | true |
f6340be4641a873ec0148a9b34aca719c73902f5 | Ruby | fgfl/two-player-math-game | /Player.rb | UTF-8 | 372 | 3.609375 | 4 | [] | no_license | class Player
@@MAX_LIFE = 3
attr_accessor :name, :answer
attr_reader :life
def initialize(name = "")
self.name = name
self.life = @@MAX_LIFE
self.answer = ""
end
def self.MAX_LIFE
@@MAX_LIFE
end
def isDead?
self.life < 1
end
def lose_one_life
self.life = life - 1
end
... | true |
9de5d9030d78dfc0494f0256ac6cf8633300b237 | Ruby | tca/bbsexp | /lib/bbsexp/dialect.rb | UTF-8 | 1,317 | 2.546875 | 3 | [
"BSD-2-Clause"
] | permissive | module BBSexp
module Dialect
module ClassMethods
attr_accessor :exps, :brackets, :end_exp, :no_parse
attr_reader :regexp, :end_exp
def self.extended(by)
by.instance_exec do
@exps = {}
end
end
def initialize
@brackets ||= '[]'
@no_parse ||= ... | true |
cfbf63b0c13741b2db3b670c3d6c87b39d3a0942 | Ruby | penders89/launch-school | /intro_to_ruby/final_exercises/ex17.rb | UTF-8 | 465 | 3.578125 | 4 | [] | no_license | hash1 = {shoes: "nike", "hat" => "adidas", :hoodie => true}
hash2 = {"hat" => "adidas", :shoes => "nike", hoodie: true}
if hash1 == hash2
puts "These hashes are the same!"
else
puts "These hashes are not the same!"
end
# this program will output true as the hashes are the same
# the ordering is different, but thi... | true |
d0efb5b6b7d090e86b8c168fe29e3436f58a4162 | Ruby | NullVoxPopuli/authorizable | /lib/authorizable/generators/authorizable/permissions/templates/permissions.rb | UTF-8 | 1,422 | 2.953125 | 3 | [
"MIT"
] | permissive | module Authorizable
# the following class is a definition of all permissions in your system
# and is independent of
class Permissions
# The following is just copied from the Authorizable README.md
#
# There are a couple ways that permissions can be defined.
#
# If you like calling methods fo... | true |
9f8acead05a2b4f97535b06074a504006c927758 | Ruby | akashkumargautam/wordlist | /app/controllers/word_controller.rb | UTF-8 | 2,578 | 3.203125 | 3 | [] | no_license | class WordController < ApplicationController
def index
end
#To see the list of words available in our database
def list
@words=Word.find(:all)
end
def enterwords
end
#to calculate the hamming distance between 'u' and 'v'
def hamm(u,v)
h=0
k=u.length
for i in (0..k-... | true |
25b2fe67dc4f5e43cae172cac755a612abb8cd0e | Ruby | Edgar-Cortez/AppAcademyOpen | /02-Software Engineering Foundations/03-RSpec/rspec_exercise_2/lib/part_1.rb | UTF-8 | 1,811 | 4.4375 | 4 | [] | no_license | def partition(arr, num)
# setup empty arrays for the numbers less than and greater than given num
lower = []
greater = []
# iterate through arr
arr.each do |ele|
# check if the current element is less than the given number
if ele < num
# shovel into lower [] if true
lower << ele
else
... | true |
b12217c733a10494df62789768459ea94e041271 | Ruby | DeeLMind/HfEngine | /STGFramework/HighLevelRenderer/Sprite.rb | UTF-8 | 1,195 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require_relative "./Graphics2D.rb"
class Sprite
attr_reader :texture
attr_accessor :src_rect
attr_accessor :angle
attr_accessor :opacity
attr_accessor :z
attr_accessor :dest_rect
attr_accessor :color_mod
attr_accessor :viewport
attr_accessor :ox, :oy
attr_accessor :hmirror, :vmirror
def initialize(t)
se... | true |
bab77322b4a592cc4a3b963dbc0192ac4953e4f9 | Ruby | ayarem21/RoR-Ruby-Basics | /1_Lesson/49.rb | UTF-8 | 252 | 3.0625 | 3 | [] | no_license | =begin
Дан целочисленный массив. Найти количество элементов, расположенных перед первым минимальным.
=end
a = [-1, 4, -2, 5, -6, 6, 7, -5]
puts a[0...a.index(a.min)].size
| true |
2a02f5d2f3789ca32ff4fcf7929ff6fbd2ed34c5 | Ruby | bookest/hiveminder | /test/test_hiveminder.rb | UTF-8 | 1,637 | 2.609375 | 3 | [] | no_license | require 'test/unit'
require 'hiveminder'
class BaseTest < Test::Unit::TestCase
class Foo < Hiveminder::Base
self.collection_name = "Foo"
end
def test_element_path
assert_equal '/=/model/Foo/id/1.xml', Foo.element_path(1)
end
def test_collection_path
assert_equal "/=/search/Foo/__order_by/id.xml... | true |
4d409ea76c07f13aa06131ef4dec3877cc55e07d | Ruby | justbdigital/siyentorails | /app/services/trendsndeals_parser.rb | UTF-8 | 1,275 | 2.953125 | 3 | [] | no_license | class TrendsndealsParser < ParserBase
ITEMS_URL = "http://www.trendsndeals.com/?p=%s"
def retrieve
data = []
10.times do |time|
response = conn.get ITEMS_URL % (time + 1)
data << response.body
end
data
end
def transform data
data.flat_map do |item|
process item
end
... | true |
366a99e648b17aba3ed317e6ecd7cdadfe615109 | Ruby | DaisyMolving/bubble_sort_algorithm | /bubblesort.rb | UTF-8 | 436 | 3.171875 | 3 | [] | no_license | class Bubblesort
def cycle_sort(list)
unsorted = list.length
while 0 < unsorted
order(list)
unsorted -= 1
end
list
end
def order(list)
current_index = 0
while current_index < list.length
next_index = current_index + 1
if list[current_index] != list.last && list[current_index] > list[next... | true |
05abb4105e512a6bbcbc7be205220bd57428677b | Ruby | yangsong8/rubric_improvement | /app/controllers/response_score_records_controller.rb | UTF-8 | 10,262 | 2.640625 | 3 | [] | no_license | class ResponseScoreRecordsController < ApplicationController
require 'statsample'
def index
#median_grades_of_each_artifact_and_each_question
#add_liberal_agreement_and_conservative_agreement_to_question_qualities_by_teams
#calculate_pearson_and_spearman_value_between_each_response_score_and_median_scor... | true |
50804f29319cd232711e5812d2f67123331f8fa5 | Ruby | donas11/Napakalaki-Ruby | /lib/PruebaNapakalaki.rb | UTF-8 | 2,033 | 2.96875 | 3 | [] | no_license | # To change this template, choose Tools | Templates
# and open the template in the editor.
module Napakalaki
require_relative 'prize'
require_relative 'bad_consequence'
require_relative 'treasure_kind'
require_relative 'monster'
#Consulta: Monstruos con nivel de combate >10
#def self.combatLevel10 (... | true |
5835147c60a3b7bb3743efb766849dcd8b4e8635 | Ruby | davidrenz60/postit | /lib/sluggable.rb | UTF-8 | 912 | 2.703125 | 3 | [] | no_license | module Sluggable
extend ActiveSupport::Concern
included do
before_save :generate_slug!
class_attribute :slug_column
end
def generate_slug!
new_slug = to_slug(self.send(self.class.slug_column.to_sym))
obj = self.class.find_by(slug: new_slug)
count = 2
while obj && obj != self
new... | true |
0376a0914aa8fec26837c8f49b2963c5c5b71776 | Ruby | r-spiel/solar-system | /solarsystem.rb | UTF-8 | 721 | 3.671875 | 4 | [] | no_license | class Solar_system
attr_reader :star_name, :planets
def initialize(star_name)
@star_name = star_name
@planets = []
end
def add_planet(planet)
@planets << planet
end
def list_planets
string_list_of_planets = "Planets orbiting #{star_name}:"
@planets.each_with_index do |planet, i| #bc ... | true |
2c753f5f33e86cddea8e15fee7695a5318fced61 | Ruby | apnuyen/anagram-detector-v-000 | /lib/anagram.rb | UTF-8 | 195 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Your code goes here!
class Anagram
attr_accessor :term
def initialize(term)
@term = term
end
def match(anagram)
anagram.select {|i| i.chars.sort == term.chars.sort}
end
end
| true |
93ec0681aa529968df544769727b18bb8d623146 | Ruby | rennes-on-rails/tinisculapp | /app/models/question.rb | UTF-8 | 3,205 | 2.671875 | 3 | [] | no_license | require 'typhoeus'
require 'yajl'
class Question
attr_accessor :number, :solution
def initialize(hash={})
hash.each do |k, v|
self.send("#{k}=", v)
end
end
end
module Minisculus
class NotAcceptable < StandardError
attr_reader :code
def initialize(code=406, message=nil)
message ||=... | true |
1b001849d54c3a4341e12df99af2f25b60477441 | Ruby | teokigi/PDA_submition | /specs/specs_card_game.rb | UTF-8 | 717 | 2.734375 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/reporters')
Minitest::Reporters.use!
Minitest::Reporters::SpecReporter.new
require_relative('../card_game.rb')
class CardGameTest < Minitest::Test
def setup
@card01 = Card.new('spades',1)
@card02 = Card.new('hearts',2)
@cards = [@card01,@card02]
end
def test_0... | true |
3d672fbd1a7fd36cbcf84b5bf1cfb18f2cc4519a | Ruby | MrAlexLau/braise | /examples/craise_usage.rb | UTF-8 | 469 | 3.265625 | 3 | [
"MIT"
] | permissive | require 'braise'
require 'ansi'
include Braise
arr = [1, 2, 3]
# Braise.configure({:color => ANSI.red}) # set default font color to red
# Braise.configure({:color => ANSI.on_green}) # set default background color to green
Braise.configure({:color => ANSI.white_on_yellow}) # set default font color to white and backgr... | true |
cce09f063e14978f7183d512ef0b4b4deca431d5 | Ruby | nikhil405/ruby_questions_set_2 | /questions/4.rb | UTF-8 | 67 | 3.328125 | 3 | [] | no_license | #Print 15 times the string "Qwinix".
puts ['qwinix'].cycle(15).to_a | true |
cf9c704022ac447b6bcd469aa06f55f65525157a | Ruby | wspurgin/ruby-os | /lib/ruby-os/srpt_scheduler.rb | UTF-8 | 1,017 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'ruby-os/scheduler'
class RubyOS::SrptScheduler < RubyOS::Scheduler
# This scheduler expects that PCBs in the queue respond to
# :remaining_processing_time as part of their accounting information
def next_proc(queue_identifier, current_proc=nil)
super
queue_manager[queue_identifier].sort_by!(&:... | true |
9e3215ea00a635d9f167b3bb2c49e71651c8abcd | Ruby | AhmadShahSeerat/say-hello-ruby | /say_hello.rb | UTF-8 | 425 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # def say_hello(name = "Ruby Programming")
# puts "Hello #{name}!"
# end
# say_hello()
# def say_hello(name = "Ruby programmer")
# puts "Hello, #{name}
# end
# say_hello("Gabriela")
# def say_hello(name="Ruby Programmer!")
# puts ("Hello #{name}!")
# end
# say_hello("Kent Beck")
# def say_hello(name)
# put... | true |
f7a6963bbdb4ea2d83986b494e186d8451cdae41 | Ruby | versality/GildedRose-challenge | /lib/gilded_rose/item_behavior/base.rb | UTF-8 | 501 | 2.625 | 3 | [] | no_license | module GildedRose::ItemBehavior
class Base
def initialize(item, database_item)
@item = item
@database_item = database_item
end
protected
def update_quality
return if @item.quality > 50
end
def change_quality(modifier)
if @item.quality + modifier < 0
@item.qual... | true |
efdb006140d30eac12733daff373cc436d06b54c | Ruby | myildiz17/ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-chi01-seng-ft-062220 | /test3.rb | UTF-8 | 1,774 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms. K"],
:white => ["Queenie", "Andrew", "Ms. K", "Alex"],
:brown => ["Queenie", "Alex"]
},
:gender => {
:male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"],
:female => ["Queenie",... | true |
d5fdfade0d379c536778e374ae16e2f2c94f83a9 | Ruby | No6Kitsunegasaki/japanese_associated_keywords | /test/test_japanese_associated_keywords.rb | UTF-8 | 1,467 | 2.8125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'test/unit'
require 'test/unit/rr'
require 'japanese_associated_keywords'
class TestMock
def initialize(site)
@site = site
end
def get(words)
'OK : ' + @site
end
end
class TestJapaneseAssociatedKeywords < Test::Unit::TestCase
def setup
JapaneseAssociatedKeywords.const_... | true |
d4630a7b59947d4de83f1d8f056b8937db2d41a2 | Ruby | mattantonelli/Euler | /largestprime.rb | UTF-8 | 274 | 4.1875 | 4 | [] | no_license | # The goal of this problem is to find the largest prime factor for the number 600,851,475,143
num = 600851475143
factor = 2
while factor < num
if num % factor == 0
num /= factor
factor = 2
else
factor += 1
end
end
puts "The largest prime factor is: " + num.to_s
| true |
5cca5ebf7f153983ed0c8318586aaea31ebb493d | Ruby | blindaa121/aA_Classwork | /W4D1/knight_travails.rb | UTF-8 | 1,824 | 3.671875 | 4 | [] | no_license | require_relative "queue"
require_relative "tree_node"
class KnightPathFinder
attr_reader :considered_positions
def self.valid_moves(curr_pos)
# find 8 possible moves from passed in pos
result = []
directions = [[-2,-1],[-2,1],[2,-1],[2,1],[1,2],[1,-2],[-1,2],[-1,-2]]
# max... | true |
84f65f1433db9a152b18145f6580e2c45973163e | Ruby | sheerun/sidekiq-unique-jobs | /spec/support/shared_examples/a_lockable_lock.rb | UTF-8 | 1,658 | 2.546875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
RSpec.shared_examples "a lock implementation" do
it "can be locked" do
expect(process_one.lock).to eq(jid_one)
end
context "when process one has locked the job" do
before { process_one.lock }
it "has locked process_one" do
expect(process_one).to be_locked
end... | true |
590753148a23dfb2a2c957802a224d7555db57af | Ruby | AlexandreL0pes/hacker-rank-solutions | /save-princess.rb | UTF-8 | 1,913 | 3.90625 | 4 | [] | no_license | #!/bin/ruby
# Link
# https://www.hackerrank.com/challenges/saveprincess
def displayPathToPrincess(n, grid)
grid = Grid.new(n, grid)
if not grid.is_valid
raise "Grid validation error"
end
grid.get_bot_coordinates
grid.get_princess_coordinates
puts grid.get_path
end
class Grid
attr_reader :n, :mat... | true |
a81ea11af9634291e4382cae446fe39de69682bf | Ruby | mikeblatter/automation_object | /lib/automation_object/state/_base.rb | UTF-8 | 2,441 | 2.96875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../helpers/composite'
module AutomationObject
module State
# Parent composite class
class Base < ::AutomationObject::Composite
# @return [AutomationObject::Driver::Driver]
attr_accessor :driver
# @return [AutomationObject::BluePrint::Composi... | true |
df8c15db7831a65a7eede6fab2f93f3c9e0a64e4 | Ruby | CThunderW/Labs | /day_18_ruby_basics/for_to_100.rb | UTF-8 | 98 | 3.703125 | 4 | [] | no_license | print "Give me anumber below 100.\n"
number = gets.chomp.to_i
for n in number..100
puts n
end | true |
e7d57aa1b8ffb7239e44866e4160faa7056ffe30 | Ruby | roman/rack-router | /spec/generation/params_fallback_spec.rb | UTF-8 | 3,202 | 2.65625 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe "When generating URLs" do
describe "a simple route" do
it "uses the fallback params to populate required parameters that were not specified" do
prepare do |r|
r.map "/:one/:two", :to => FooApp, :name => :simple
... | true |
7cb0afeb69d28e80303fc36220f4eba4e0f0e613 | Ruby | ramosjm/money_tracker_project | /little_bits_app/models/transaction.rb | UTF-8 | 2,330 | 3.21875 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
require_relative('./merchant.rb')
require_relative('./tag.rb')
class Transaction
attr_accessor :amount, :tag_id, :merchant_id
attr_reader :id, :date_added
def initialize(transaction)
@id = transaction['id'].to_i if transaction['id']
@amount = transaction['amount'].to... | true |
d229b970c001b721948030adcf35a3c3a828e502 | Ruby | svenskan/database | /proverbs/bin/json | UTF-8 | 1,773 | 3.0625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'json'
require 'nokogiri'
class Record
ATTRIBUTES = %i(expression equivalent translation meaning)
attr_accessor *ATTRIBUTES
def self.parse(element)
attribute = element.css('i')[0]
return nil if attribute.nil?
record = Record.new
record.expression = attribute.text
... | true |
5d370cfb4345242a6711ba7122133992420b60c6 | Ruby | richaSha/Prime-Shifting | /lib/prime_shifting.rb | UTF-8 | 394 | 3.46875 | 3 | [
"MIT"
] | permissive | class PrimeNumber
def find_prime(num)
start_count = 2
number_range = (start_count..num).to_a
while num > start_count
number_range.each do |number|
if (number % start_count == 0) & (start_count != number) & (number_range.include?(number))
number_range.delete(number)
end
... | true |
6ffaa1142dfc99929767c60e487b25543362218d | Ruby | tdyer/ruby-hashes | /demo/hash_methods_done.rb | UTF-8 | 3,205 | 3.265625 | 3 | [] | no_license | state_abbr = {
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'I... | true |
6071a8e245200267fc54ea7d9082d6c709854364 | Ruby | psyho/bogus | /lib/bogus/stubbing/matchers/with_arguments.rb | UTF-8 | 563 | 2.828125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Bogus
class WithArguments
attr_reader :predicate
def initialize(&predicate)
@predicate = predicate
end
def matches?(args)
predicate.call(*args)
end
def self.matches?(opts = {})
stubbed = opts.fetch(:stubbed)
recorded = opts.fetch(:recorded)
return false ... | true |
e709a9fa758f645977cd7a9fb47d09dbfd63e6bb | Ruby | RasPat1/ctci | /c1/Urlify.rb | UTF-8 | 2,600 | 4.0625 | 4 | [] | no_license | # Replace all spaces in a sring with "%20"
# Assume that the string has sufficient space at
# the end to hold the additional characters, and that
# you are given the "true" length of the string.
class Urlify
# Linear but requires N extra space
def call(str, true_length)
result_str = ''
space_char = "02%"
... | true |
cab356e5ee20caccc8dc6ee70af0b31c4624ae79 | Ruby | lucaminudel/TDDwithMockObjectsAndDesignPrinciples | /TDDMicroExercises/Ruby/turn_ticket_dispenser/turn_number_sequence.rb | UTF-8 | 109 | 2.796875 | 3 | [] | no_license | class TurnNumberSequence
@turn_number = 0
def self.get_next_turn_number
@turn_number += 1
end
end
| true |
e28cb9badda4e63f449e68957a3c334f52c1c62e | Ruby | OllieRemus/ttt-6-position-taken-rb-v-000 | /lib/position_taken.rb | UTF-8 | 608 | 3.6875 | 4 | [] | no_license | # code your #position_taken? method here!
#def position_taken?(board, index)
# if board["X".to_i || "O".to_i] == board["X".to_i || "O".to_i]
#elsif board[" ".to_i || "".to_i] !=
#else board[nil] !=
#end
#end
# true = spot taken
# false = spot free
#def position_taken?(board, index)
#if board[" ".to_i] == "X" |... | true |
4432848afe5b161e8625d18628715d9c8dcc493f | Ruby | glhngr/ttt-3-display_board-example-cb-gh-000 | /lib/display_board.rb | UTF-8 | 302 | 2.640625 | 3 | [] | no_license | def display_board
cells= " "
cellsSeparator="|"
stripedRow="-----------"
puts cells+cellsSeparator+cells+cellsSeparator+cells
puts stripedRow
puts cells+cellsSeparator+cells+cellsSeparator+cells
puts stripedRow
puts cells+cellsSeparator+cells+cellsSeparator+cells
end
display_board
| true |
9da32bc581f3860ef39eabfc262df5a4e38039c9 | Ruby | sbalsom/rubypython | /spec/refcnt_spec.rb | UTF-8 | 2,659 | 2.8125 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/spec_helper.rb'
def get_refcnt(pobject)
raise 'Cannot work with a nil object' if pobject.nil?
if pobject.kind_of? RubyPython::RubyPyProxy
pobject = pobject.pObject.pointer
elsif pobject.kind_of? RubyPython::PyObject
pobject = pobject.pointer
end
RubyPython::Macros.... | true |
672b94bca262e0bc0c534741e02c067c1c256177 | Ruby | ogikun/Ruby_lessons | /hello.rb | UTF-8 | 614 | 3.671875 | 4 | [] | no_license | border = "---------------------"
#コメント
=begin
コメント
コメント
print "hello world"
puts "hello world" #改行
p "hello world" #デバッグ
puts border
#変数
#- 英小文字、アンダーバー
msg = "hello world"
puts msg
msg = "hello world again"
puts msg
puts border
#定数
# - 英大文字
VERSION = 1.1
puts VERSION
VERSION = 1.2
puts VERSION
puts bord... | true |
589b8990efda762a874797f8f257fac425282bb0 | Ruby | newpolaris/flaming-archer | /auth.rb | UTF-8 | 1,571 | 2.53125 | 3 | [] | no_license | #!/user/bin/env ruby
require 'rubygems'
require 'twitter'
require 'net/http'
require 'uri'
require 'open-uri'
require 'nokogiri'
require 'parallel'
ENV['CONSUMER_KEY'] = "EnKqwgHH47GZHzq9k4p7DdsuQ"
ENV['CONSUMER_SECRET'] = "xBEzDFUkEUVMsdEMfVCrhWvWa9GSIsVbMbhAj6wzUNLvwP8vsY"
ENV['ACCESS_TOKEN_SECRET'] = "H5m4D4EkcFZuT... | true |
51113e368ac502225744f38cfd0ef5932ff16df0 | Ruby | nathangthomas/Enigma | /lib/offsets.rb | UTF-8 | 597 | 3.34375 | 3 | [] | no_license | require 'date'
class Offsets
attr_reader :date, :numbers, :offset_keys
def initialize(date = Time.now.strftime("%d%m%y"))
@date = date
@numbers = last_4_digits_of_squared_date
@offset_keys = offset_generator
end
def date_squared
@date.to_i ** 2
end
def last_4_digits_of_squared_date
(... | true |
b46ffea9ab961b4d4b7c7f625ca70f1d27f70561 | Ruby | DawidGaleziewski/LocalUdemyRuby | /184_add_or)subtract_time.rb | UTF-8 | 563 | 3.609375 | 4 | [] | no_license | start_of_year= Time.new(2018, 1, 1)
p start_of_year
#example changing by one mont
p start_of_year - (60 * 60 * 24 * 40) #we add/subtract by seconds
#challange- what date represent that day of the year
puts
def find_day_of_the_year(number)
current_day = Time.new(2016, 1, 1)
one_day = (60 * 60 * 24)
#use # .yday m... | true |
11ba2f83a88c934ce47882d8a4d190ea29c45607 | Ruby | martin-sokolov/learn_ruby | /13_xml_document/xml_document.rb | UTF-8 | 953 | 3.03125 | 3 | [] | no_license | class XmlDocument
private
def method_missing(name, *args, &block)
define_method(name, *args)
send(name, *args, &block)
end
def define_method(name, *args)
define_singleton_method(name) do |attributes={}, &block|
inner_content = block.call if block
XmlElement.new(name, att... | true |
479ef7c2329c712dd419458cf3a16db36ad8f565 | Ruby | cmb84scd/katas | /unique_in_order/lib/unique_in_order.rb | UTF-8 | 141 | 2.8125 | 3 | [] | no_license | def unique_in_order(iterable)
if iterable.is_a? String
iterable = iterable.split(//)
end
iterable.chunk(&:itself).map(&:first)
end
| true |
f98cc1bb0c4ade3f9fcfd969d2915ccdc217f1f7 | Ruby | expajp/project_euler | /level04/77/problem-77.rb | UTF-8 | 937 | 3.75 | 4 | [] | no_license | # coding: utf-8
# Problem 77
=begin
10は素数の和として5通りに表すことができる:
7 + 3
5 + 5
5 + 3 + 2
3 + 3 + 2 + 2
2 + 2 + 2 + 2 + 2
素数の和としての表し方が5000通り以上になる最初の数を求めよ.
=end
require 'prime'
# get primes patterns
def gpp(n, h)
return 0 if n == 1 || (n < h && n != 0)
return 1 if n == 0 || (h == 2 && n%h == 0)
# p "n:#{n} h:#{h}"
... | true |
2557bf1db16a69d220c65d8b8cd12741910070bc | Ruby | Christineneiman9/vjotcneiman | /vendor/gems/datamapper/lib/data_mapper/adapters/.svn/text-base/mysql_adapter.rb.svn-base | UTF-8 | 3,961 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'data_mapper/adapters/sql_adapter'
require 'data_mapper/support/connection_pool'
begin
require 'mysql'
rescue LoadError
STDERR.puts <<-EOS.gsub(/^(\s+)/, '')
This adapter currently depends on the \"mysql\" gem.
If some kind soul would like to make it work with
a pure-ruby version that'd be supe... | true |
3579bcb4043f721be6af6e5d1533fdb1baf86269 | Ruby | NicoleCarpenter/tic-tac-toe-ruby | /board.rb | UTF-8 | 4,840 | 3.265625 | 3 | [
"MIT"
] | permissive | class Board
attr_accessor :active_board, :winning_combinations, :played_moves
attr_reader :board_positions
def initialize(board_size)
@board_size = board_size
@rows = find_rows
@board_positions = (1..square_board).to_a.map{|n| n.to_s}
@active_board = Array.new(square_board, " ")
@winning_comb... | true |
f38e450fbf360702b009b993d99301710ace1600 | Ruby | renanmaringolo/dino | /session_4/lesson_4.rb | UTF-8 | 782 | 3.390625 | 3 | [] | no_license | # sendo assim, de acordo com as lessons anteriores, faça um exercício para imprimir
# no screen as propriedades de uma string com vários valores separados por pipe (|).
# devem ser mostradas uma embaixo da outra, de acordo com os exercícios.
# implemente o código necessário para fazer com que o resultado no screen sej... | true |
13147dbce006ec0451f26197e4c6d4d9285b155e | Ruby | wuchenxi/bringing-it-all-together-v-000 | /lib/dog.rb | UTF-8 | 1,470 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog
attr_accessor :name, :breed, :id
def initialize name: nil, breed: nil, id: nil
@name=name;@breed=breed;@id=id
end
def self.create_table
sql = <<-SQL
CREATE TABLE IF NOT EXISTS dogs (
id INTEGER PRIMARY KEY,
name TEXT,
breed TEXT
)
SQL
DB[:... | true |
af165e4ac6324088c8e245b4bc99da0e31c381f8 | Ruby | edin/raytracer | /ruby/RayTracer.rb | UTF-8 | 7,632 | 3.359375 | 3 | [
"MIT"
] | permissive | require "imageruby"
class Vector
attr_accessor :x , :y , :z
def initialize(x, y, z)
@x, @y, @z = x, y, z
end
def self.scale(k, v)
Vector.new(k * v.x, k * v.y, k * v.z)
end
def self.minus(v1, v2)
Vector.new(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z)
end
def self.plus(v1, v2)
Vector.new(v1... | true |
9a6ee7aafb6d1b215e81a3acb8623bb3e8465384 | Ruby | whitneykidd/final_assessment_be_2003 | /spec/features/doctors/new_spec.rb | UTF-8 | 1,409 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe "Create New Doctor" do
describe "from a hospital's show page" do
it "can click link to add doctor to hospital" do
grey = Hospital.create(name:"Grey Sloan Memorial Hospital", address: "123 Save Lives Rd", city: "Seattle", state: "WA", zip: "98101")
meredith = Doct... | true |
02f82f33d84e23ac5f5b716bb89dc14eda4065be | Ruby | pelensky/the_well_grounded_rubyist | /chapter_05/global_scope.rb | UTF-8 | 502 | 3.578125 | 4 | [] | no_license | =begin
$gvar = "I'm a global!"
nongvar = "I'm not global"
class C
def examine_global
puts $gvar
puts nongvar # ~> NameError: undefined local variable or method `nongvar' for #<C:0x007feb2b820ff0>
end
end
c = C.new
c.examine_global
=end
class Person
def whole_name
n = $first_name + " "
n << "#{$... | true |
fa0fb6eb1950ba1e599a972a04bd745678049dab | Ruby | zoho/projects-ruby-wrappers | /lib/projects/model/Tasklog.rb | UTF-8 | 890 | 2.703125 | 3 | [
"MIT"
] | permissive | # $Id$
module Projects
module Model
require File.dirname(__FILE__) + '/Log'
# * This class is used to make an object for Tasklog.
class Tasklog < Log
private
attr_accessor :taskId, :taskName
public
# * Set the task id.
#
# ==== Parameters
#
# * taskId... | true |
3ead0257e6a18626284c72f2484305d6911ea0d3 | Ruby | mars167/iniparse | /spec/spec_helper_spec.rb | UTF-8 | 5,549 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
# --
# ============================================================================
# Empty array.
# ============================================================================
# ++
describe 'An empty array' do
it 'should not pass be_section_tuple' do
expect([]).not_to be_section_tuple
... | true |
1517caf7e76ef70ec77cca25003446ccb98ec72d | Ruby | crguezl/treetop-sexp-parser | /main.rb | UTF-8 | 163 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'pp'
require './parser'
contents = '(this "is" a test( 1 2.0 3))'
contents = File.open(ARGV.shift, "r").read if ARGV.length > 0
pp Parser.parse(contents)
| true |
d83386dc30ad4afd6554a87aa899a9384e763d74 | Ruby | kobe1104/Stack-queue | /window_range.rb | UTF-8 | 600 | 3.4375 | 3 | [] | no_license |
# O(n^2)
def windowed_max_range(arr, size)
current_max_range = nil
arr.each_with_index do |e, i|
# debugger
break if i + size > arr.size
min_max = arr[i...(i+size)].minmax
diff = min_max.last - min_max.first
if current_max_range.nil? || diff > current_max_range
current_max_range = diff
... | true |
28d446ff87bd98b5ed8cd5648352d97e50e9511f | Ruby | tjp2021/battleship | /lib/player.rb | UTF-8 | 287 | 2.59375 | 3 | [] | no_license | require "./lib/grid.rb"
class Player
attr_reader :player_turn, :winner, :known_spaces
def get_patrol_coordinates
gets.chomp
end
def isolate_patrol_coodinates
get_patrol_coordinates.
end
#method for player turn
#method to decide winner or loser
#method for known_spaces
end
| true |
a0af33473af6ea03749b470724ba34588beb7b80 | Ruby | osbornegabriel/Rail_Fence_Cypher_Codewars | /rail_fence_cypher.rb | UTF-8 | 3,311 | 3.4375 | 3 | [] | no_license | # # starting_string = "WEAREDISCOVEREDFLEEATONCE"
# # encoded_string = "WECRLTEERDSOEEFEAOCAIVDEN"
#########################
###### RAIL ENCODER #####
#########################
def rail_encode(s,rail_count)
phrase = s.dup
rail_indexes = Array(0..(rail_count-1))
rails = create_rails(rail_indexes)
lines = build... | true |
6643bbe73044180bd50aeb049801d9b6799fe980 | Ruby | oruki/taiju_bb | /app/controllers/test_controller.rb | UTF-8 | 805 | 2.75 | 3 | [] | no_license | class TestController < ApplicationController
def calculate
if request.post?
@errors = []
arg1 = convert_float(:arg1)
arg2 = convert_float(:arg2)
op = convert_operator(:operator)
if @errors.empty?
begin
@result = op.call(arg1, arg2)
rescue Exception => err
@result = err.message
end... | true |
c89be86910e438b5a8fa108562fb9c4627cbc816 | Ruby | ssteeg-mdsol/openapi3-generator | /gems/gems/prawn-table-0.2.2/manual/table/style.rb | UTF-8 | 777 | 2.546875 | 3 | [
"Apache-2.0",
"GPL-3.0-only",
"GPL-2.0-only",
"Ruby"
] | permissive | # encoding: utf-8
#
# We've seen how to apply styles to a selection of cells by setting the
# individual properties. Another option is to use the <code>style</code> method
#
# <code>style</code> lets us define multiple properties at once with a hash. It
# also accepts a block that will be called for each cell and can b... | true |
4da22a806413e26608c44a641c6672d5502b1e44 | Ruby | s030827/peoplefinder | /app/presenters/membership_changes_presenter.rb | UTF-8 | 4,030 | 2.6875 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | # frozen_string_literal: true
class MembershipChangesPresenter < ChangesPresenter
SENTENCE_EXCEPTIONS = %w[group_id role leader subscribed].freeze
class ::Hash
def to_membership_set
MembershipChangeSet.new(deep_symbolize_keys)
end
end
def format(raw_change_set)
h = {}
raw_change_set&.ea... | true |
208682d469f6a0859634b227b93d211537f847dc | Ruby | zeroLaming/al_tweets | /lib/tweet_store.rb | UTF-8 | 946 | 2.734375 | 3 | [] | no_license | class TweetStore
class << self
# Fetch tweets from the API and store them in the database.
# Determine if a tweet already exists by looking it up from
# its (API) ID. If it does, inc the view count.
#
# Return an array of new tweets. In real life we'd probably
# want to make use of these (ie ... | true |
6feabd596d9d693b777946b3b9137000ed43e89b | Ruby | fuji-nakahara/nlp100 | /src/11.rb | UTF-8 | 328 | 3.34375 | 3 | [
"MIT"
] | permissive | # タブ1文字につきスペース1文字に置換せよ.
# 確認にはsedコマンド,trコマンド,もしくはexpandコマンドを用いよ.
file_path = File.expand_path('../data/hightemp.txt', __dir__)
res = File.read(file_path).tr("\t", ' ')
raise 'Failed!' if res != `tr '\t' ' ' < #{file_path}`
puts res
| true |
8c6d2c24f934682cdd934b82d80a29aa83ca3beb | Ruby | ajseemar/The-Nature-of-Code-Examples-in-Ruby | /chp02_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.rb | UTF-8 | 434 | 2.515625 | 3 | [] | no_license | # The Nature of Code
# http://natureofcode.com
load_library :vecmath
require_relative 'mover'
def setup
size(383, 200)
srand(1)
@movers = Array.new(15) { Mover.new(rand(1.0 .. 4), rand(width), 0) }
end
def draw
background(255)
@movers.each do |m|
wind = Vec2D.new(0.01, 0)
gravity = Vec2D.new(0, 0.1 ... | true |
c5d4221dd52b05929346bc0424383611af76fcf4 | Ruby | oliviacubela/potter_world | /lib/potter_world/api.rb | UTF-8 | 502 | 2.6875 | 3 | [
"MIT"
] | permissive | class API
def self.get_char_data
response = RestClient.get("https://www.potterapi.com/v1/characters?key=$2a$10$dzneyObJXfMmDwbSJS1LtONfqk526gSxHIl/ukaNki3OOSDwyw.JK")
characters = JSON.parse(response.body)
characters.each do |character|
CharacterDirectory.new(character)
end
end
d... | true |
6c8225f3f63f2b45ebce528b814790a9e513139a | Ruby | DarlingL/test_touch | /features/android/screens/touch_screen.rb | UTF-8 | 810 | 2.546875 | 3 | [] | no_license | class Touchid
def initialize
@login = 'finger_sign_in_button'
@msglogin = 'You have successfully logged in'
@msgerror = 'Fingerprint Authentication failed.'
end
def wait_for_element(type, identificator, time)
manage.timeouts.implicit_wait = (time)
@driver.find_... | true |
f14f3d310b567c5f19432b192a94358bc5c8e148 | Ruby | VirginiaDooley/my-collect-online-web-pt-092418 | /lib/my_collect.rb | UTF-8 | 202 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(array)
i = 0
empty_array = []
while i < array.length
empty_array << yield(array[i]) #pushes each element of array into new empty_array
i += 1 #counter
end
empty_array
end | true |
dcf59615149749baf7e2c13f772e2096507b8ea3 | Ruby | denniscolburn/qa_hwy_2020 | /spec/flat_file_to_raw_spec.rb | UTF-8 | 1,336 | 2.625 | 3 | [] | no_license |
describe 'Flat file to raw' do
before(:each) do
@env = ENV["env"]
end
context 'loading the flat file' do
it 'does not transform the data' do
isbn = rand(1000000000000..9999999999999)
puts "test isbn is " + isbn.to_s
title = ["Book 1", "Book 2", "Book 3", "Book 4", "Book 5"].sample
... | true |
6595dc0d2a1baada97af19e13ab2e79ad84f6f07 | Ruby | el-doble/the-Odin-Project-Ruby-test-first-ruby | /03_simon_says/spec/lib/simon_says.rb | UTF-8 | 526 | 4.0625 | 4 | [] | no_license | def echo(input_text)
input_text
end
def shout(input_text)
input_text.upcase
end
def repeat(input_text, n = 2)
([input_text] * n).join(' ')
end
def start_of_word(input_text, n)
input_text.slice(0, n)
end
def first_word(input_text)
input_text.split.to_a[0]
end
def titleize(input_text)
sentence = input_te... | true |
f90c6f42a87e65adbbb29bec5cc1c306a6af72e7 | Ruby | gbudiman/violet-rails2 | /app/models/concerns/skillable.rb | UTF-8 | 3,744 | 2.703125 | 3 | [] | no_license | # frozen_string_literal: true
module Concerns
module Skillable
class MissingSkillPrerequisite < StandardError
attr_reader :skill, :all, :missing, :has
def initialize(hsh)
@skill = hsh[:skill]
@all = hsh[:all]
@missing = hsh[:missing]
@has = @all - @missing
su... | true |
a16618863410d70340e33549cf0064ceecbb1bee | Ruby | BebopVinh/partial-locals-lab-online-web-ft-021119 | /db/seeds.rb | UTF-8 | 784 | 2.609375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | student_names = ['Bob', 'Robert', 'Roberta', 'Shirley', 'Shelby']
student_names.each do |name|
Student.create(name: name, hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
end
75.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker... | true |
22e69dd856739a20a703b34a022dd22cb8887a44 | Ruby | realtime-system/gamemachine | /server/lib/game_machine/game_systems/objectdb_proxy.rb | UTF-8 | 1,851 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | module GameMachine
module GameSystems
class ObjectDbProxy < Actor::Base
include GameMachine::Commands
aspect %w(ObjectdbGet Player)
# Generic way for a client to save state. We scope the id to the
# player to prevent hacked clients from writing stuff they shouldn't.
def self.sav... | true |
4173242d024458545db43f72f6df44eba10098d0 | Ruby | lits-ruby-and-rails-course/Homeworks-Group-2 | /oct_29/_Michael/home.rb | UTF-8 | 463 | 3.625 | 4 | [] | no_license | def out_names(arr)
arr = arr.each_slice(5).to_a
arr.each_with_index do |name, index|
puts "Group#{index + 1}: #{name}"
puts "----"
end
end
array = ["Hulk", "Spiderman", "Batman", "Captain America", "Frodo",
"Bruce Willis", "Jackie Chan", "Johny Deep", "Al pacino",
"Homer ... | true |
7fbf4a482d7a0bdd98a99784e42ade8110fb2896 | Ruby | lukaskf/heeler_tech | /lib/tasks/import_csv.rake | UTF-8 | 2,496 | 2.859375 | 3 | [] | no_license | namespace :import_csv do
desc "Imports data from CSV to App & DB"
task import_technicians: :environment do
puts "Importing Technicians Data..."
filename = File.join Rails.root, "lib/assets/technicians.csv"
counter = 0
CSV.foreach(filename, headers:true) do |row|
... | true |
6d1120bde9da0ddc221a04c5d59922e44f497e5a | Ruby | jlee4219/project_euler | /17.rb | UTF-8 | 822 | 4.09375 | 4 | [] | no_license | NAMES = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
HUNDRED = "hundred"
AND = "and"
def get_na... | true |
d66b25bf649fee1959baea112e1d87139e131d2b | Ruby | yanbinkang/problem-bank | /interview_cake/temparature_checker.rb | UTF-8 | 960 | 3.703125 | 4 | [] | no_license | class TempTracker
def initialize
@total_sum = 0
@num_temperatures = 0.0
@max_temp = nil
@min_temp = nil
@max_occurances = 0
@occurances = [0] * 111
@mode = nil
@mean = nil
end
def insert(temperature)
@num_temperatures += 1
@total_sum += temperature
@mean = @total_sum ... | true |
bc5569b5c739b8fee3ba726b9cecef32e7d83702 | Ruby | hovermeyer/advent-of-code | /2019/day-08/puzzle_01.rb | UTF-8 | 194 | 2.796875 | 3 | [] | no_license | file_data = File.read("input.txt")
layers = file_data.scan(/\w{150}/).min{|x,y| x.chars.count("0")<=>y.chars.count("0")}
puts layers
puts layers.chars.count("1") * layers.chars.count("2")
| true |
ed3663605dbb895f050e79c2f32a0956266dd1bf | Ruby | bentrojan/OOP-Project | /tic_tac_toe/tictactoe.rb | UTF-8 | 2,914 | 3.796875 | 4 | [] | no_license | class Game
attr_reader :ttt, :x, :o, :player_number
# initializes a board and two players
def initialize
@ttt = Board.new
@ttt.sample_board
@x = Player.new("X")
@o = Player.new("O")
@player_number = 0 # player turn counter
end
# plays the game
def play
loop do
@ttt.view_board
if @ttt.winne... | true |
0226a2d1650c01c0b9091986ae1af16cdb4e786d | Ruby | Nitemaeric/coding-lessons | /ruby/1-programming-fundamentals/data_types.rb | UTF-8 | 347 | 4.03125 | 4 | [] | no_license | # Data Types
60 # int (60, 7, 0, -2)
60.5 # float (5.1, 5.0, -5.2)
"Daniel" # string ("Seekster", 'Hello')
true # boolean
nil # null value
puts "50 is an #{50.class}"
puts "60.7 is a #{60.7.class}"
puts "'Hi' is a #{'Hi'.class}"
puts "true is a #{true.class}"
puts "false is a #{false.class}"
pu... | true |
1a4f6569701f44b51236944dfd50e67fef991e36 | Ruby | rubyworks/quarry | /lib/quarry/template.rb | UTF-8 | 3,446 | 2.90625 | 3 | [
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"Ruby"
] | permissive | module Quarry
# Template encapsulates a directory to be used as scaffolding.
#
# In Quarry's colloquial terminology this may be called a *mine*.
#
class Template
#
# Initialize new template.
#
# @param [String] path
# Location of the template in the file system.
#
def initializ... | true |
2e8fa73006fc3aa20695346444f9eb92f0e5b6fc | Ruby | johnjvaughn/ls_course_170 | /counter.rb | UTF-8 | 1,131 | 3.078125 | 3 | [] | no_license | require "socket"
def parse_request(request_line)
# i.e. GET /?rolls=2&sides=6 HTTP/1.1
http_method, path_and_query, http = request_line.split
path, query = path_and_query.split('?')
params = {}
if query
params = query.split('&').each_with_object({}) do |pair_str, hash|
key, value = pair_str.split('... | true |
b7c4942efcffe15b7a682ddd5bdce6e393aff29c | Ruby | neumerance/imprezify-v2 | /app/models/common_name_value.rb | UTF-8 | 212 | 2.546875 | 3 | [] | no_license | class CommonNameValue < ApplicationRecord
def completed?
name.present? && value.present?
end
def completion_percentage
%w(name value).map { |x| self.try(x.to_sym).present? ? 50 : 0 }.sum
end
end
| true |
de00a29ecb17004798c6dcbfae52ff96787bdd19 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/1024bef234e547088a4af14f0b12d7af.rb | UTF-8 | 206 | 3.1875 | 3 | [] | no_license | class Gigasecond
def initialize(date)
@date = date
end
def date
gigasecond = 10 ** 9
minutes = gigasecond / 60
hours = minutes / 60
days = hours / 24
@date + days
end
end
| true |
533a9df893ed99d8a2a4513f52d52ee5b08504b4 | Ruby | Gilblasse/ruby-collaborating-objects-lab-online-web-ft-110419 | /lib/mp3_importer.rb | UTF-8 | 310 | 2.78125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require_relative '../env.rb'
class MP3Importer
attr_accessor :path
def initialize(file_path)
@path = file_path
end
def files
Dir["#{@path}/*.mp3"].collect {|f| f[21..-1]}
# binding.pry
end
def import
files.each {|file| Song.new_by_filename(file)}
end
end
| true |
58833d807e0aeec81cd71b997c9a61838c7c8509 | Ruby | ramky/ruby_intro_week1 | /ruby_exercises/exercise.rb | UTF-8 | 2,079 | 4.5 | 4 | [] | no_license | #!/usr/bin/env ruby
# 1. Use the "each" method of Array to iterate over [1, 2, 3, 4, 5, 6,
# 7, 8, 9, 10], and print out each value.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each { |i| puts i }
#2. Same as above, but only print out values greater than 5.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each { |i| puts i if i > 5 }
#3. Now,... | true |
bce334c57f3141691c939c21f02d53b512a770d3 | Ruby | paulzay/bubble_sort | /sort.rb | UTF-8 | 654 | 3.75 | 4 | [] | no_license | def bubble_sort(arr)
(arr.length - 1).times do |number|
(arr.length - number - 1).times do |num|
arr[num], arr[num + 1] = arr[num + 1], arr[num] if arr[num] > arr[num +1]
end
end
arr
end
def bubble_sort_by(arr)
(arr.length - 1).times do |number|
(arr.length - number - 1).times do |num|
... | true |
715d9151b2777e7519f1261305348cd25ec68575 | Ruby | asajoarder/Tap-Translate | /build.rb | UTF-8 | 1,535 | 2.671875 | 3 | [] | no_license | require 'yaml'
Bundler.require
class Builder
attr_reader :config
def initialize config_path
@config = YAML.load File.read(config_path)
end
def build!
run :compile, "Compiling coffee"
run :package, "Packaging"
run :push, "Pushing to device" if config[:push_to_device]
puts "Done!"
end
... | true |
f998637f5fb21576f13c53a46c40492c66e5d88b | Ruby | kellyarwine/rpn_calculator | /lib/data_input.rb | UTF-8 | 112 | 2.71875 | 3 | [] | no_license | class DataInput
attr_accessor :components
def initialize(data)
@components = data.split(" ")
end
end | true |
c3ab994463ce03eb793c6370ade98260130d7a40 | Ruby | nicholsk18/app_academy_open | /software_engineering_foundations/tic_tac_toe/v1_with_test/lib/game.rb | UTF-8 | 1,003 | 3.890625 | 4 | [
"MIT"
] | permissive | require_relative "board"
require_relative "human_player"
class Game
def initialize(player_1_mark, player_2_mark)
@board = Board.new
@player_1 = HumanPlayer.new(player_1_mark)
@player_2 = HumanPlayer.new(player_2_mark)
@current_player = @player_1
end
def switch_turn
if @current_player == @pl... | true |
b1630909c28fc7072067e5bbdaf395b390f66b2a | Ruby | anton-wego/pabrik | /app/models/slip.rb | UTF-8 | 2,043 | 2.78125 | 3 | [] | no_license | class Slip < ApplicationRecord
belongs_to :employee
validates :employee_id, presence: true
before_validation :calculation_over_time_and_workday_count
before_validation :calculation_salary
VALID_DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
SALARY = '4000000'
def slip_filen... | true |
cf7f6df860334f4d1f3889fad7bc80ed3590301c | Ruby | Albin-Willman/advent | /2017/11/test.rb | UTF-8 | 395 | 3.03125 | 3 | [] | no_license | #!/usr/bin/env ruby
require "./task.rb"
test_input = {
'ne,ne,ne' => 3,
'ne,ne,sw,sw' => 0,
'ne,ne,s,s' => 2,
'se,sw,se,sw,sw' => 3
}
test_input.each do |input, expected|
hg = HexGrid.new(input)
res = hg.effective_distance
if res == expected
puts "#{input} OK"
else
put... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.