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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
773754cade52309ce1ff2a7b02721e4643aa21ef | Ruby | limanxian/datx_ruby | /lib/datx_ruby/district.rb | UTF-8 | 1,146 | 2.71875 | 3 | [
"MIT"
] | permissive | module DatxRuby
class District
include DatxRuby::Common
def initialize
@data = IO.binread(datx)
@index_size = Util.bytes2long(@data[0], @data[1], @data[2], @data[3])
end
def self.datax_path=(path)
$datx_path ||= path
end
def find(ip)
raise "Invalid IP address" unle... | true |
592a53c1fffb64ceb369bbf32a8e92fb40c26294 | Ruby | CodingDojoDallas/ruby-oct-2016 | /ken_nguyen/assignments/Ruby OOP/dog/dog.rb | UTF-8 | 398 | 3.4375 | 3 | [] | no_license | #dog class
require_relative 'Mammal'
class Dog < Mammal
# def initialize
# super
# end
def pet(*val)
for i in val
@health += 5*i
end
self
end
def walk(*val)
for i in val
@health -= 1*i
end
self
end
def run(*val)
for i in val
@health -= 10*i
end
... | true |
c7a67ea40275755a621cbb6d825d2429ece667ba | Ruby | StewartMacLeman/Week-5-Project | /gallery/models/exhibit.rb | UTF-8 | 1,692 | 3.34375 | 3 | [] | no_license | require_relative('../db/sql_runner')
class Exhibit
attr_accessor :id, :exhibit_name, :type, :year, :artist_id
def initialize(options)
@id = options['id'].to_i
@exhibit_name = options['exhibit_name']
@type = options['type']
@year = options['year']
@artist_id = options['artist_id'].... | true |
cb6581ec41a22b3804c3e7104a772241fca11320 | Ruby | sgrif/euler-challenges | /012.rb | UTF-8 | 139 | 3.15625 | 3 | [] | no_license | x, y = 0, 0
while true
y += x
x += 1
r = 0
for z in 1..Math.sqrt(y)
r += 2 if y % z == 0
end
puts "#{x} #{y}"
exit if r > 499
end
| true |
21de5eb81d3bf52c01a5c4c38d8580209a24c064 | Ruby | jacegu/teaching_ruby | /array2/array2_set1.rb | UTF-8 | 445 | 3.21875 | 3 | [] | no_license | class Array2
def empty?
length == 0
end
def include?(element)
i = 0
while i < length
return true if at(i) == element
i += 1
end
false
end
def index(object)
for i in 0..(length - 1)
return i if at(i) == object
end
nil
end
def clear
delete_at(0) unti... | true |
5541d0355fd41ebc92554f5a178cd3edae8f3a68 | Ruby | hackingbeauty/collective_intelligence | /4/lib/search_engine.rb | UTF-8 | 6,509 | 2.984375 | 3 | [] | no_license | require 'open-uri'
require 'rubygems'
require 'hpricot'
require 'sqlite3'
require 'ruby-debug'
class Crawler
IGNORE_WORDS = ['the','of','to','and','a','in','is','it']
attr_accessor :con
def initialize(dbname)
@con = SQLite3::Database.new(dbname)
end
def self.del
@con.close
end
def dbcommit
@con.commi... | true |
d0ca1cdae69a1d71b42f67980a0717ea16e7a025 | Ruby | gary-lgy/cvwo_todo_list | /app/models/task.rb | UTF-8 | 1,043 | 2.640625 | 3 | [
"MIT"
] | permissive | class Task < ApplicationRecord
has_and_belongs_to_many :tags
# task title and user_id cannot be blank
validates :title, :user_id, presence: true
# scopes for retrieving different categories of tasks
scope :completed, -> { where completed: true }
scope :ongoing, -> { where completed: false }
# toggle be... | true |
d3b9704948eb02870bb9dabc0c0d8172af694b56 | Ruby | mathildathompson/wdi_sydney_feb | /students/tom_dane/romans/romans.rb | UTF-8 | 2,238 | 4.6875 | 5 | [] | no_license | # Modern Roman numerals ... are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero.
# To see this in practice, consider the example of 1990.
# In Roman numerals 1990 is MCMXC:
# 1000=M 900=CM 90=XC
# 2008 is written as MMVIII:
# 2000=MM 8=VIII
... | true |
df872690cacac70f0245775b310a8433d834a42d | Ruby | yinm/ruby-book-codes | /sample-codes/chapter_07/column_7.05.rb | UTF-8 | 492 | 4.1875 | 4 | [] | no_license | # コラム:メソッドの有無を調べる`respond_to?`
s = 'Alice'
# Stringクラスはsplitメソッドを持つ
s.respond_to?(:split) #=> true
# nameメソッドは持たない
s.respond_to?(:name) #=> false
# ----------------------------------------
def display_name(object)
if object.respond_to?(:name)
# nameメソッドが呼び出せる場合
puts "Name is <<#{object.name}>>"
else
... | true |
bab0769c4bca2f2c76ce3bd33d0c5f1b375d4321 | Ruby | divanikus/salus | /spec/salus_countdownlatch_spec.rb | UTF-8 | 1,791 | 2.953125 | 3 | [
"BSD-3-Clause"
] | permissive | require "spec_helper"
RSpec.describe Salus::CountDownLatch do
let(:latch) { Salus::CountDownLatch.new(3) }
let(:zero_count_latch) { Salus::CountDownLatch.new(0) }
it 'raises an exception if the initial count is less than zero' do
expect {
Salus::CountDownLatch.new(-1)
}.to raise_error(ArgumentErro... | true |
69dacd09484646c60fe5eb8f9ab391e0676a6024 | Ruby | flavio/active_resource_test_helper | /lib/active_resource_test_helper/ohm/model.rb | UTF-8 | 571 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'ohm'
module Ohm # :nodoc:
# Adds some convenience methods to Ohm::Model[http://github.com/soveran/ohm].
class Model
# Convert the model to hash.
def to_hash
hash = {:id => self.id.to_i}
self.attributes.each do |attr|
hash[attr] = self.send attr
end
hash
end
... | true |
e1414ce94af8f1d1c9f4273769774bfd87733bd6 | Ruby | iqqmuT/ship-calendar | /calendar.rb | UTF-8 | 4,162 | 2.765625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
require 'rubygems'
require 'google/api_client'
require 'google/api_client/auth/file_storage'
class GoogleCal
def initialize(calendar_id, credential_store_file)
@client = Google::APIClient.new(
:application_name => 'Ship Calendar',
:application_version => '1.0.0')
file_storage = ... | true |
f6cfc8a5f6c2fbd1ac7c2d76029163e3706032ae | Ruby | jasonnoble/deck_of_cards | /lib/deck.rb | UTF-8 | 413 | 3.09375 | 3 | [] | no_license | require './lib/card'
class OutOfCards < Exception; end
class Deck
def initialize
# Create some cards
end
def cards
# Return the cards
end
def draw(number_of_cards=1)
# Return number_of_cards from the list of cards
end
def shuffle
# Make the card order random!
end
def to_s
# A ... | true |
a3f83faf1b6a36f456186c7d5b3725946210ffa1 | Ruby | akaohiroki/furima-30204 | /spec/models/user_spec.rb | UTF-8 | 6,605 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー新規登録' do
context '新規登録できるとき' do
it '全ての項目が入力がされていれば登録できる' do
expect(@user).to be_valid
end
it 'emailに@が含まれていれば登録できる' do
@user.email = 'test@com'
... | true |
47c7cd35ce2667e88083cbe2650eb7d468bacf9b | Ruby | noomdalv/rails_authentication | /app/models/user.rb | UTF-8 | 893 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class User < ApplicationRecord
attr_accessor :remember_digest
has_many :posts
before_create :create_remember_token
before_save { email.downcase! }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.... | true |
6ac8e97a8a3440ea0c1a914a441c11d224644411 | Ruby | sijos/homeworks | /JS_problems/JumpStart/Step1 hw/solution/w1d3_hw.rb | UTF-8 | 612 | 4.6875 | 5 | [] | no_license | # Wild Sum
# Define a method, #wild_sum(n) that sums all the numbers less than n that are:
# - Divisible by 2 or divisible by 3
# - Not divisible by both 2 and 3
# ex: wild_sum(16) ==> 2 + 3 + 4 + 8 + 9 + 10 + 14 + 15 ==> 65
# def wild_sum(n)
# (0...n).select{|e| (e % 2 == 0 || e % 3 == 0) && e % 6 != 0 }.redu... | true |
1b5d81eaae48acec8fc05e50e3836053bd06bfd2 | Ruby | kirualex/Flamingo | /vendor/bundle/ruby/2.6.0/gems/jwt-2.2.2/lib/jwt/base64.rb | UTF-8 | 361 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
require 'base64'
module JWT
# Base64 helpers
class Base64
class << self
def url_encode(str)
::Base64.encode64(str).tr('+/', '-_').gsub(/[\n=]/, '')
end
def url_decode(str)
str += '=' * (4 - str.length.modulo(4))
::Base64.decode64(str.tr(... | true |
ca9edb762c8fe1d8999abdfcba93e4b9155af78e | Ruby | chueyng/WDI12_Homework_LearningLab | /AngieNg/week_11/11-advanced/recursion/factorial.rb | UTF-8 | 303 | 4.5 | 4 | [] | no_license | def factorial_iterative(n)
result = 1
while n >= 1
result = result * n
n -= 1
end
result
end
def factorial(n)
if n <= 1 # Check for the base case
1 # Return the base case
else
n * factorial(n - 1)
end
end
puts factorial_iterative(5) # => 120
puts factorial(5) | true |
c964ab3b56d46c680bf5482091512c63d2066128 | Ruby | sd-pocket-gophers-2017/assessment | /part-1/shipping_container.rb | UTF-8 | 732 | 3.171875 | 3 | [] | no_license | class ShippingContainer
attr_reader :destination, :max_crates, :crates
attr_accessor :max_weight
def initialize(args)
@destination = args.fetch(:destination)
@max_weight = args.fetch(:max_weight)
@max_crates = args.fetch(:max_crates)
@crates = args.fetch(:crates, [])
end
def current_weight
... | true |
752b5e5c67fb4ee859c7fb77af1aa9eb3b378bdf | Ruby | altryuji/bookstore | /db/seeds.rb | UTF-8 | 1,937 | 2.78125 | 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 |
9ebb4a53e2afd7e028c4f79408b80e8e1b600292 | Ruby | JOlivier92/99Cats | /nine_cats/app/models/cat_rental_request.rb | UTF-8 | 770 | 2.546875 | 3 | [] | no_license | class CatRentalRequest < ApplicationRecord
include Comparable
validates :cat_id, :start_date, :end_date, presence: true
validate :overlapping_requests
belongs_to :cat,
foreign_key: :cat_id,
class_name: :Cat
def overlapping_requests
# find rental requests of specific cat_id
# all of the ... | true |
63b5b4664d991e59f68da32f62c6be0e6423ff8f | Ruby | klatour324/cribs | /lib/house.rb | UTF-8 | 490 | 3.625 | 4 | [] | no_license | class House
attr_reader :price,
:address,
:rooms
def initialize(price, address)
@price = price
@address = address
@rooms = []
end
def add_room(room)
@rooms << room
end
def above_market_average?
false
end
def rooms_from_category(category)
bedrooms =... | true |
6000db471a96e54c0955cceda4e6a4f6c29c0e36 | Ruby | cgeib79/weekend_homework_week_02 | /room.rb | UTF-8 | 854 | 3.171875 | 3 | [] | no_license | class Room
attr_reader :room_name , :guest_collection
def initialize(room_name)
@room_name = room_name
@room_capacity = room_capacity
@guest_collection = []
@song = []
end
def guest_collection_count()
return @guest_collection.length()
end
def add_guest_collection(new_guest)
@gues... | true |
43f61104e64f2c08ae9cb4fc71e0065d44d0ddf7 | Ruby | Jakub-Pietrzyk/SPOJ_accepted_tasks | /accepted_wiatraczki.rb | UTF-8 | 3,115 | 3.296875 | 3 | [] | no_license |
def tworzenie(ile,skretnosc)
podstawa = [['*','*'],['*','*']]
if ile == 0
return podstawa
elsif skretnosc ==true
tab = []
for i in 0...ile+2
tab[i] = []
end
tab[0][0] = '*'
tab[0][ile+1] = '*'
tab[ile+1][0] = '*'
tab... | true |
6ed3c219e39c7cc2e34047a5bd38bf88ea155aa8 | Ruby | toddschw/Code_wars_kata | /the_old_switcheroo.rb | UTF-8 | 223 | 3.515625 | 4 | [] | no_license | # Code Wars Kata - The old switcheroo, 7 kyu
def vowel_2_index(string)
phrase = string.chars.map.with_index(1) do |char,i|
["a","e","i","o","u","A","E","I","O","U"].include?(char) ? i : char
end
phrase.join
end
| true |
64f3370aad2b9fb6462343013daa0e5a22d69e28 | Ruby | MarcusMellorMIM/green_grocer-london-web-career-042219 | /grocer.rb | UTF-8 | 2,512 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def consolidate_cart(cart)
# code here
consolidated_cart={}
counter=0
cart.each do
cart[counter].each do |k,v|
if consolidated_cart[k]
consolidated_cart[k][:price]=cart[counter][k][:price]
consolidated_cart[k][:clearance]=cart[counter][k][:clearance]
consolidated_cart[k][:cou... | true |
d1303d41618c40d6f4f473e5c8cb48a756f70da1 | Ruby | willherrick/learn_ruby | /04_pig_latin/pig_latin.rb | UTF-8 | 3,112 | 4.03125 | 4 | [] | no_license | # If a word begins with a vowel sound, add an "ay" sound to the end of the word.
# If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.
# banana = ananabay
# cherry = errychay
# three = eethray
# this = isthay
def translate(input)
inputArray = inp... | true |
07ee7373bb5cddf696134772ce4bbceb385eb7f4 | Ruby | tagty/nand2tetris | /projects/07/vm_translator.rb | UTF-8 | 4,920 | 3 | 3 | [] | no_license | class Parser
attr_reader :commands
def initialize(file_name)
@commands = []
File.open(file_name) { |file| file.each do |line|
line.chomp!
line.sub!(/\/\/.*/m, '')
line.strip!
unless line.empty?
@commands << line
end
end }
@index = 0
end
def commands?
!@... | true |
ba75f7f2682b05537decb90c5960dcd7f6300fcb | Ruby | aschreck/sorting_suite | /bubble/lib/bubble_sort.rb | UTF-8 | 501 | 3.265625 | 3 | [] | no_license | class BubbleSort
def sort (numbers)
n = numbers.length
loop do
swapped = false
(n-1).times do |i|
#require 'pry'; binding.pry
if numbers[i] > numbers[i + 1]
numbers[i], numbers[i + 1] = numbe... | true |
66f55cecf057bc4c5f48bf645fe35ac7b0d4ecb4 | Ruby | Aaron-McD/connect-four | /main.rb | UTF-8 | 749 | 4.03125 | 4 | [] | no_license | require_relative "lib/game.rb"
# Example code to run the game and work with the API
$symbols = []
def get_symbol
input = gets.chomp
while input.length > 1 || $symbols.include?(input)
puts "Please just enter a single character that has not been used: "
input = gets.chomp
end
$symbols.ap... | true |
b652868535859d92e1a98c5766d75e57fe63190d | Ruby | JiyoonJeon/coderbyte-coderbyte-by-Rudy-Language | /Ex_Oh.rb | UTF-8 | 286 | 3.34375 | 3 | [] | no_license | def ExOh(str)
# code goes here
x_num = str.scan('x').length
o_num = str.scan('o').length
if x_num == o_num
return true
else
return false
end
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
ExOh(STDIN.gets)
| true |
8586526c9e134839df853c3ea42c9cc618abc49d | Ruby | damned/egdate | /lib/egdate.rb | UTF-8 | 343 | 2.625 | 3 | [] | no_license | require_relative 'egdate/example_parser'
require_relative 'egdate/format'
class EgDate
def initialize(date)
@date = date
end
def like(example, format_provider: Eg::Date::Format, example_parser: Eg::Date::ExampleParser.new)
format_provider.format(example_parser.parse(example)).print date
end
private
... | true |
148d985e56f65544319d5b7850ca79c4e1b1d43a | Ruby | VijayEluri/codes | /ruby/doGuess.rb | UTF-8 | 709 | 3.3125 | 3 | [] | no_license | #coding:utf-8
puts "#########################"
puts "# #"
puts "# SAYI TAHMİN OYUNU #"
puts "# #"
puts "#########################\n\n"
sabit = 15
i = 0
while 2>1
print "tahmininizi giriniz:"
num = gets.chomp
if num.to_i == sabit
... | true |
672cd51892c4061679e37b19d0817e5338221b93 | Ruby | AliOsm/kontests | /app/services/leet_code_service.rb | UTF-8 | 1,244 | 2.578125 | 3 | [
"MIT"
] | permissive | class LeetCodeService < SiteService
CONTESTS_URL = 'https://leetcode.com/graphql?query={%20allContests%20{%20title%20titleSlug%20startTime%20duration%20__typename%20}%20}'
REQUEST_TYPE = RequestType::HTTP
DATA_OBJECT_TYPE = DataObjectType::JSON
private
def extract_contests data
data['data']['allContests']... | true |
e6a2c0dc25ffb7859db1db6dd6c0eb165d5b842b | Ruby | tranvictor/lion_attr | /spec/lion_attr_spec.rb | UTF-8 | 9,517 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
class TestRedis
include Mongoid::Document
field :foo, type: Integer
field :bar, type: Integer
field :mew, type: Float
field :baz, type: Float
field :qux, type: String
include LionAttr
live :foo, :bar, :mew, :qux
end
describe LionAttr do
before(:each) do
@test = TestRedis.ne... | true |
c17cc32f4ee0b9de511e8e30f63872a1ab2f6b97 | Ruby | antonhalim/playlister-cli-bk-002-public | /spec/genre_spec.rb | UTF-8 | 1,750 | 3.265625 | 3 | [] | no_license | describe Genre do
before(:each) do
Genre.reset_all
end
let(:genre){Genre.new}
it "can initialize a genre" do
expect(genre).to be_an_instance_of(Genre)
end
it "has a name" do
genre.name = 'rap'
expect(genre.name).to eq('rap')
end
it "has many songs" do
genre = Genre.new.tap { |g| ... | true |
130d1037e3756380d0ef86499e4dacf5d8a1f1d2 | Ruby | cogma/Introduction-to-Algorithms | /allcode/contact.rb | UTF-8 | 1,162 | 2.921875 | 3 | [] | no_license | class Contact
attr_accessor("name","number","left","right")
def initialize(name,number)
self.name = name
self.number = number
self.left = nil
self.right = nil
end
end
def find_contact(p,n)
if p.name == n
p
else
if n < p.name
find_contact(p.left, n)
else
find_contact(p.... | true |
4461846e49629a0ec8aac90baf8411b3ae2e0cd8 | Ruby | francosta/collections_practice_vol_2-london-web-career-040119 | /collections_practice.rb | UTF-8 | 708 | 3.796875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def begins_with_r(array)
array.each {|word| if word[0] != "r" then return false end}
true
end
def contain_a(array)
words_with_a = []
array.each {|word| if word.split("").include?("a") then words_with_a << word end}
words_with_a
end
def first_wa(array)
array.each {|word| if word[0..1] =... | true |
c43308b58e9dee6e696c5921a9ba966bd204ee75 | Ruby | katebeavis/Battleships-Web | /lib/server.rb | UTF-8 | 1,043 | 2.953125 | 3 | [] | no_license | require 'sinatra/base'
require_relative 'board'
require_relative 'game'
require_relative 'ship'
require_relative 'player'
require_relative 'cell'
require_relative 'water'
class Battleships < Sinatra::Base
game = Game.new
board = Board.new(size: 2, content: Cell)
board.grid.each{|cell| cell.last.content = Water.... | true |
049120018d3a007c036644dbaf4c0033343021cd | Ruby | Jolomono/introduction-to-programming-with-ruby | /1_the_basics/1.rb | UTF-8 | 150 | 3.875 | 4 | [] | no_license | # Add two strings together that, when concatenated, return your first and last name as your full name in one string.
puts "Rainy" + " " + "McDowell"
| true |
1764924081e5c02167925999b7fec3af2a7a8f36 | Ruby | Ventajou/praxis-exception-handler | /lib/exception_handler.rb | UTF-8 | 1,483 | 2.96875 | 3 | [
"MIT"
] | permissive | # Exception Handler plugin
#
# Praxis allows overriding its default exception handler, however only one
# override is possible. This plugin replaces the default handler and allows
# attaching additional handlers that can all be called. This lets us separate
# concerns, for example we can have one handler for logging an... | true |
545fd97a08b6a89568f6cd7760cb602911ad59a2 | Ruby | worashf/leetcode-solutions | /ruby/Q313/Q313.rb | UTF-8 | 714 | 3.453125 | 3 | [] | no_license | # David Lin
# Complexity: Time/Space O(n)
# Description:
# Leetcode - 313. Super Ugly Number
# Dynamic Programming, pls refer to problem 264, using the same approach.
# @param {Integer} n
# @param {Integer[]} primes
# @return {Integer}
def nth_super_ugly_number(n, primes)
uglys = [0,1]
p = Array.new(primes.lengt... | true |
8a1d71d170b51270d303bf1b67c8531883949c02 | Ruby | vxvinod/Learn-Ruby | /open-existing-method/range.rb | UTF-8 | 365 | 3.515625 | 4 | [] | no_license | class Range
def by(step)
x=self.begin
puts exclude_end?
puts self.end
if exclude_end?
puts "inside exclude"
while x < self.end
yield x
x += step
end
else
puts "outside exclude"
while x <= self.end
yield x
x += step
end
end
end
end
(2..10).by(2) ... | true |
45e6a397621bb8460c835f5f13b113b6635c9d4e | Ruby | birkirb/acapela | /lib/acapela/config.rb | UTF-8 | 1,124 | 2.515625 | 3 | [] | no_license | require 'yaml'
require 'uri'
module Acapela
class Config
attr_reader :application,
:version,
:environment,
:login,
:password,
:protocol,
:target_url
DEFAULT_PROTOCOL = '2'
DEFAULT_VERSION = '1-30'
DEFAULT... | true |
2b6b45e85480025d2b549b23a0c67fe8a422b09e | Ruby | Theoonetj/method-arguments-lab-online-web-ft-120919 | /lib/introduction.rb | UTF-8 | 144 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def introduction(name, language)
puts "Hi, my name is #{name} and I am learning to program in #{language}"
end
introduction("Theo", "ruby") | true |
75aa14f9bc41706787ab94844a27147cfa0cecaf | Ruby | ravithejreddy/emojisays | /main.rb | UTF-8 | 3,133 | 2.546875 | 3 | [] | no_license | require 'sinatra'
# require 'sinatra/reloader' #reload the sinatra webpage
# require 'pry' #load in pry
require 'pg' #to connect to postgres
require_relative 'db_config'
require_relative 'models/user'
require_relative 'models/leader'
require_relative 'models/vote'
enable :sessions
helpers do
#
# def clicked?
... | true |
a1e90c9c8e2adc40e84b9d7e11474aaedde176e3 | Ruby | neontuna/project_tdd_minesweeper | /spec/player_spec.rb | UTF-8 | 904 | 2.734375 | 3 | [] | no_license | require 'player'
context Player do
describe "#get_coords" do
it "gets and validates format of coordinates for a cell from the player" do
allow( subject ).to receive(:gets).and_return("bad", "still bad", "1,1")
allow( subject ).to receive(:print)
expect( subject.get_coords ).to eq( [1,1] )
... | true |
f97003c053cf4c380b00ef1be970cb0aeda9cada | Ruby | Mr00zie/notes | /WarmUps/Methods/Compression/solution/solution.rb | UTF-8 | 369 | 3.40625 | 3 | [] | no_license |
def compress(word)
indexOne = 0
indexTwo = 1
result = ""
while(indexOne < word.length)
while(word[indexOne] == word[indexTwo] && indexTwo < word.length)
indexTwo += 1
end
if(indexTwo - indexOne > 1)
result += (indexTwo - indexOne).to_s
end
result += word[indexOne]
indexOne =... | true |
4280df821481906de6cbb80f86e9aeb11454eafb | Ruby | rublen/TN-Ruby-Basics | /part_5/route.rb | UTF-8 | 1,048 | 3.484375 | 3 | [] | no_license | require_relative 'instance_counter'
require_relative 'station'
class Route
include InstanceCounter
set_counter
attr_reader :stations
def initialize(start_station, end_station)
@stations = [start_station, end_station]
validate!
register_instance
end
def show
stations.map(&:name).join('-')... | true |
e95df847f78d116168485b34086096c9852447ee | Ruby | apoc64/caesar_cipher | /test/caesar_test.rb | UTF-8 | 1,057 | 3.234375 | 3 | [] | no_license | # YOUR TESTS GOES HERE
# # I PITY THE FOOL WHO DOESNT WRITE TESTS
require 'minitest/autorun'
require 'minitest/pride'
require './lib/caesar'
class CaesarTest < MiniTest::Test
def setup
@caesar = Caesar.new
end
def test_it_can_cipher
coded = @caesar.eng_to_cipher("the quick brown fox jumps over the lazy dog", 3)
... | true |
90107718d715a97613c457899c8c516dad4ec9b6 | Ruby | dkaushal99352/devbootcamp | /rubyprogs/boggle.rb | UTF-8 | 695 | 3.75 | 4 | [] | no_license |
boggle_board = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
def create_word(board, *coords)
coords.map { |coord| board[coord.first][coord.last]}.join("")
end
def get_row(board, row)
board[row].inspect
end
def ge... | true |
72ee84c4ee8e2db813b8ba6d9fbb1ea63719e34f | Ruby | Galaxylaughing/Bipartition-Graph | /lib/possible_bipartition.rb | UTF-8 | 1,995 | 3.5625 | 4 | [
"MIT"
] | permissive | def is_visited(visited_list, current_puppy)
return !visited_list[current_puppy].nil?
end
def no_more_enemies(current, enemy_count)
return current >= enemy_count
end
def mark_as_visited(visited_list, current_puppy, current_group_color)
visited_list[current_puppy] = current_group_color
end
def incompatible_group... | true |
8302d18c319145c8b428a67d8dc47b5021cf0823 | Ruby | mkrumholz/flash_cards | /flashcard_runner.rb | UTF-8 | 379 | 2.84375 | 3 | [] | no_license | # extra trivia source: https://www.parents.com/fun/activities/indoor/trivia-questions-for-kids/
require './lib/card_generator'
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/round'
require './lib/game'
card_generator = CardGenerator.new("cards.txt")
deck = Deck.new(card_generator.cards)... | true |
ed25191e9560103ed3f6ee09e2ad7d031768cd23 | Ruby | suhnylla/git_tryout | /git_file.rb | UTF-8 | 58 | 2.84375 | 3 | [] | no_license | 10.times {
puts "hello"
}
def sayHello
puts "hello"
end | true |
c156df3c8f484240a18d03ec4e25681ca301bcb8 | Ruby | rodrigo-rocha-dias/capy | /spec/dropdown_spec.rb | UTF-8 | 669 | 2.65625 | 3 | [] | no_license |
describe "Caixa de opções", :dropdown do #tag dropdown
it "Item especifico simples" do
visit "/dropdown"
select("Loki", from: "dropdown") #dropdown = ID na tela / só funciona quando tem ID na tela
sleep (3) # temporrio
end
it "Item especifico com o find" do
visit "/dropdown"
drop = find(".a... | true |
20f84e28792f80894150edea7da273b424ebfeb8 | Ruby | bingo8670/programming-exercise | /49-simple-fraction-to-mixed-number-converter.rb | UTF-8 | 480 | 3.640625 | 4 | [] | no_license | # 除法结果变为 整数+分数的形式;
def mixed_fraction(string)
improper = Rational(*(string.split('/').map(&:to_i)))
integer = improper.to_i
fraction = improper - integer
return "#{integer}" if (fraction).numerator == 0
return "#{fraction}" if integer == 0
"#{integer} #{fraction.abs}"
end
p mixed_fraction('42/9') ... | true |
b637155f6ed78231a5e338527dbe6350109bfb8d | Ruby | saumyamehta17/algorithm_and_system_design | /graph/base.rb | UTF-8 | 1,088 | 3.640625 | 4 | [] | no_license | require 'pry'
class GraphList
attr_accessor :adjacents
def initialize
@adjacents = []
end
end
Edge = Struct.new(:src, :dst)
class Graph
attr_accessor :array, :vertices_count, :edges
def initialize(vertices_count)
@vertices_count = vertices_count
@array = Array.new(vertices_count)
@edges =... | true |
e3066863a95dc117778faf1bcae72743871ffcb0 | Ruby | muminovic/cs61aPrepCourse | /ch14/better_logger.rb | UTF-8 | 537 | 3.359375 | 3 | [] | no_license | $nesting_depth = 0
def better_log(block_description,&block)
puts (" " * $nesting_depth) + "Beginning '#{block_description}'..."
$nesting_depth += 1
returned = block.call
$nesting_depth = $nesting_depth - 1
puts (" " * $nesting_depth) + "'#{block_description}' finished, returning:
#{returned}"
end
be... | true |
1a1d096e92898a36c9822b2a400860e6235eb5be | Ruby | jamot3/AppAcademy_Challenges | /power_of_two.rb | UTF-8 | 147 | 3.40625 | 3 | [] | no_license | def is_power_of_two? num
while num >= 2
num = num.to_f / 2
end
if num == 1
return true
end
false
end | true |
d2901ad2bff558092bd90f1da7518925eeae31d2 | Ruby | UIKit0/psd.rb | /lib/psd/clipping_mask.rb | UTF-8 | 1,290 | 2.5625 | 3 | [
"MIT"
] | permissive | class PSD
class ClippingMask
def initialize(layer, png=nil)
@layer = layer
@png = png
end
def apply
return @png unless @layer.clipped?
PSD.logger.debug "Applying clipping mask #{mask.name} to #{@layer.name}"
width, height = @layer.document_dimensions
full_png = compo... | true |
3cabe6f393ae57cf650386f4f5c3b90f33ac8ddb | Ruby | MikeJGilbert42/wikivitals | /lib/exceptions.rb | UTF-8 | 784 | 2.75 | 3 | [] | no_license | module Exceptions
class WikipediaArticleError < StandardError
def initialize message = "There was a problem with the article"
@message = message
end
def message
@message
end
end
class ArticleNotFound < WikipediaArticleError
def initialize(message = "Article not found")
@mes... | true |
422721e216c4dc02ebce12bbc42c76dd406336a1 | Ruby | blackpowder/Game-of-life | /game_of_life.rb | UTF-8 | 2,950 | 3.84375 | 4 | [] | no_license | class Game_of_life
def initialize
@board = []
File.open("starting_board.txt", "r") do |file|
@content = file.read
@content.lines.each do |line|
@board << line.strip.split(//)
end
end
end
#call next turn and save the outputs to a new file
def start
puts `... | true |
5a647fca396f9c0b2ce1b548afde5ea1dc9ddfd0 | Ruby | matthewmcnew/raven | /test/models/student_test.rb | UTF-8 | 405 | 2.703125 | 3 | [] | no_license | require "minitest_helper"
class StudentTest < ActiveSupport::TestCase
it "validates presence of name" do
student = Student.new()
student.valid?.wont_equal true
student.errors.must_include :first_name
student.errors.must_include :last_name
end
it "gives the full name" do
student = Student.new... | true |
72f0a2335b46fe7cb1ced661aa0a0730adc9d6c8 | Ruby | blolol/rpg | /app/models/cached_character.rb | UTF-8 | 716 | 2.671875 | 3 | [
"MIT"
] | permissive | class CachedCharacter < SimpleDelegator
# Attributes
attr_reader :at
def initialize(character)
super character
@character = character
@at = Time.current.freeze
cache_state
end
def gear_score
@cached_gear_score
end
def level
@cached_level
end
def to_s
CharacterPresenter.... | true |
e77d0c4a5bfea0ab257b40debfbbfaf73dbfe553 | Ruby | roidrage/eventmachine-scotrubyconf | /code/em-queue.rb | UTF-8 | 233 | 2.625 | 3 | [] | no_license | require 'eventmachine'
EM.run do
queue = EM::Queue.new
popper = lambda do |msg|
puts "Popped #{msg}"
queue.pop &popper
end
queue.pop &popper
EM.add_periodic_timer(1) do
queue.push("ZOMG, MESSAGE!!")
end
end
| true |
9851db02a6e11249fc9d5a957f97c1b40c5ca5ad | Ruby | kareemgrant/contact_manager | /spec/models/person_spec.rb | UTF-8 | 736 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
describe Person do
before(:each) do
@person = Person.new(first_name: "Kareem", last_name: "Grant")
end
it "should be valid" do
person = Person.new(first_name: "Tony", last_name: "Starks")
expect(person).to be_valid
end
it "should not be valid without a first name" do
... | true |
8bc742180c74f5e9c3acf056396b2dacc507fe6e | Ruby | skolznev/LearnRuby | /Cap2 Strings.rb | UTF-8 | 10,920 | 3.734375 | 4 | [] | no_license | #Какими могут быть СТРОКИ в Ruby
s1 = 'Это строка'
s2 = 'It\'s string'
s3 = 'Смотри в C:\\Temp'
puts s1
puts s2
puts s3
puts
s4 = "Это знак табуляции: (f\tf)"
s5 = "Несколько символов забоя: xyz\b\b\b"
s6 = "Это тоже знак табуляции: f\011f"
s7 = "А это символы подачи звукового сигнала: f\a\007f"
puts s4
puts s5
puts s6... | true |
e1799b419fbb05e3ed0c789bb7de014d37e27e0a | Ruby | rickgrundy/Chunks | /spec/core_extensions_spec.rb | UTF-8 | 724 | 2.8125 | 3 | [] | no_license | require_relative "spec_helper.rb"
describe "Chunks Core Extensions" do
describe "for String" do
it "returns a class without module" do
"Array".to_class.should == Array
end
it "returns a modulised class" do
"Chunks::BuiltIn::Html".to_class.should == Chunks::BuiltIn::Html
end... | true |
89ba2963542026367172077252ad259e618ba023 | Ruby | hanazuki/adventofcode | /src/17b.rb | UTF-8 | 419 | 2.640625 | 3 | [] | no_license | caps = $<.readlines.map {|s| s.chomp.to_i }.sort_by(&:-@)
$comb = []
def dfs(i, caps, rest, used)
if i == caps.size
if rest == 0
$comb << used
end
return
end
return if rest < 0
dfs(i + 1, caps, rest - caps[i], used + [i])
dfs(i + 1, caps, rest, used)
end
dfs(0, caps, 150, [])
minnum = ... | true |
a4391154fcf1838d373766871c079959c509b428 | Ruby | mannut2014/Leetcode | /ruby/medium/construct_binary_tree_from_preorder_and_inorder_traversal.rb | UTF-8 | 768 | 3.609375 | 4 | [
"MIT"
] | permissive | # Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {Integer[]} preorder
# @param {Integer[]} inorder
# @return {TreeNode}
def build_tree(preorder, inorder)
map = {}
... | true |
f3c2c910a39fd3e17135f761deba9d96a57f24ca | Ruby | jubrad/y_support | /lib/y_support/core_ext/object/misc.rb | UTF-8 | 1,796 | 2.921875 | 3 | [
"MIT"
] | permissive | #encoding: utf-8
require 'y_support/core_ext/class'
class Object
# Assigns prescribed atrributes to the object and makes them accessible with
# getter (reader) methods. Raises NameError should any of the getters shadow /
# overwrite existing methods.
#
def set_attr_with_readers hash
hash.each_pair { |ß... | true |
6d3f755481f763660bc9331442e4013d523f5e34 | Ruby | rschultheis/hatt | /lib/hatt/blankslateproxy.rb | UTF-8 | 998 | 3.03125 | 3 | [
"MIT"
] | permissive | module Hatt
# A simple 'blankslate' class which is used to avoid namespace polution
# Provides a proxy to a parent class, in order to allow access to other hatt methods like http service objects
#
# TODO: Figure out if can/should use a BasicObject here. I know it wont work right now
# because the binding met... | true |
4b898e06a56a11d7244c7fb1b61b3e42aa7405c9 | Ruby | Dzirt232/ruby_primers_tdd | /02_calculator/calculator.rb | UTF-8 | 394 | 3.890625 | 4 | [] | no_license | def add(num1,num2)
num1 + num2
end
def subtract(num1,num2)
num1 - num2
end
def sum(array)
array.inject(0) {|sum, x| sum + x}
end
def multiply(num1, num2, num3 = 1)
num1 * num2 * num3
end
def power(num, power)
otvet = num
while power>1
otvet *= num
power -= 1
end
return otvet
end
def factorial(num)
if... | true |
66790f8e1d3f2240d75274832d57d7df6e3e1e46 | Ruby | slnwlf/ruby-oop-reading | /solutions.rb | UTF-8 | 1,636 | 4.125 | 4 | [] | no_license |
#Four times of variables in Ruby
#-local variables - defined in a method
class Customer
end
#-instance variables - available across methods for any particular instance or object
class Customer
@number_of_customers
end
#-class variables - available across different objects (car and bike example)
class Custom... | true |
ee9d9a3ce180351ed0170c27122ca8fde2259d9e | Ruby | jichen3000/colin-ruby | /test/int/s1.rb | UTF-8 | 446 | 3.140625 | 3 | [] | no_license | #TO22 = 4194304
#p TO22.class
#p 1.class
#
#p (10&2)
#
#p (1<<30)
#p ((1<<30)-1).class
#p (1<<1)
#arr = []
#512.times do |index|
# arr << (1<<index)
#end
#p arr
#
#require 'benchmark'
#Benchmark.bm do |item|
#item.report("rand") {100000.times{rand(512)}}
#item.report("512") {100000.times {|i| 1<<(rand(512)+400)}}
#en... | true |
41db3cd01928a0d56f7cb07bb85cac5f8ba60c9d | Ruby | mroman42/rbNapakalaki | /prize.rb | UTF-8 | 466 | 3.359375 | 3 | [] | no_license | #!/usr/bin/env ruby
#encoding: utf-8
module Game
# Premio al conseguir una victoria.
class Prize
# Inicializador
def initialize (treasures, levels)
@treasures = treasures
@levels = levels
end
# Métodos públicos
def getTreasures
@treasures
end
def get... | true |
80e8f428933ce5077d6d1dc21b92c208468d666f | Ruby | balaji-kmty/intro-to-programming-ls | /methods/three.rb | UTF-8 | 204 | 4.03125 | 4 | [] | no_license | # Write a program that includes a method called multiply that takes two arguments and returns the product of the two numbers.
def multiply(num_one, num_two)
num_one * num_two
end
puts multiply(20, 30)
| true |
60c45ca5b5e7cb244783f57246188c987c91ea40 | Ruby | AndreiMotinga/ctci | /arrays_and_strings/zero_matrix.rb | UTF-8 | 752 | 4.125 | 4 | [] | no_license | # Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.
class Matrix
attr_reader :matrix
def initialize(input)
@matrix = input
end
def zero
zero = matrix.map(&:dup)
zero.each_with_index do |line, line_i|
line.map! { |el| el = 0 } if rows_w... | true |
efdf5a050cf67e55cad2ede1f51ef47ea1d2b367 | Ruby | agamble/bloom | /lib/bloom/filter.rb | UTF-8 | 2,445 | 2.875 | 3 | [] | no_license | module Bloom
class Filter
attr_reader :bit_field, :nHash, :nTweak, :size
MAX_SIZE = 36000
def initialize(elements, false_positive_rate=0.01, nHash=10)
@nTweak = 1000
@size = ([( -1 * elements * Math.log(false_positive_rate)) / (Math.log(2) ** 2),
MAX_SIZE * 8].min / 8).floor... | true |
6a3ee7baa06b6a26984d9f671d579b60babe1e08 | Ruby | timoxman/inject-challenge | /spec/timject_spec.rb | UTF-8 | 673 | 3.328125 | 3 | [] | no_license | require 'Enumberable'
describe 'timject' do
it 'deals where the initial value is zero (U1)' do
expect([1,2,3].timject(0) {|result, element| result + element}).to eq 6
end
it 'deals with where the initial value is missing (U2)' do
expect([1,2,3].timject() {|result, element| result + element}... | true |
8c09d642ee40321e4749194783b012c94c7a4ef8 | Ruby | czuger/google-cal-push | /ruby/google_cal.rb | UTF-8 | 2,422 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'google/apis/calendar_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'fileutils'
class GoogleCal
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
APPLICATION_NAME = 'Google Calendar API Ruby Quickstart'.freeze
CLIENT_SECRETS_PATH = 'data/client_secrets.json'.freeze
CREDENTIA... | true |
51425750573aa05a3b93e2b5e5c0daa74066b298 | Ruby | amer519/ttt-6-position-taken-rb-nyc-fasttrack-020120 | /lib/position_taken.rb | UTF-8 | 149 | 3.109375 | 3 | [] | no_license | def position_taken?(array, ind)
if array[ind] == " " || array[ind] == "" || array[ind] == nil
return false
else
return true
end
end | true |
d584994d6b090a7d1a9654cfbea257c27f69c7b1 | Ruby | russolsen/notroff | /lib/notroff/command_processor.rb | UTF-8 | 586 | 3.015625 | 3 | [] | no_license | class CommandProcessor
def process( lines )
paragraphs = []
lines.each do |line|
cmd, text = parse_line( line )
if cmd.empty?
cmd = :text
else
cmd = cmd.sub(/^./, '').to_sym
end
para = Text.new(text, :type => cmd, :original_text => line.to_s)
paragraphs << p... | true |
f3a5006bcf95a3ee04f13d0a6638681dfe40cee2 | Ruby | face-do/motion-rails-model | /lib/motion-rails-model/model.rb | UTF-8 | 2,162 | 2.53125 | 3 | [
"MIT"
] | permissive | module RM
class Model
attr_accessor :id
@@url = ""
@@username = ""
@@password = ""
def initialize(json={})
attributes_update(json)
end
def self.find(id, &block)
x = self.new
x.fetch("#{x.class.to_s.downcase}/#{id}") do |y|
block.call(y)
end
end
de... | true |
982e006bf5d29f0a1d362f3a7416f022cc5da7c4 | Ruby | yellowjell0/phase-0-tracks | /ruby/list/todo_list.rb | UTF-8 | 313 | 3.640625 | 4 | [] | no_license | class TodoList
def initialize(array)
@array = array
end
def get_items
@array
end
def add_item(new_item)
@array.push(new_item)
end
def delete_item(item_to_delete)
@array.delete(item_to_delete)
end
def get_item(int)
@array[int]
end
end
# list = TodoList.new(["a", "b"])
# list.get_items | true |
8ef397f30255a04f37f6d47b888e724017474bd6 | Ruby | emhopkins/activerecord-tvland-v-000 | /app/models/actor.rb | UTF-8 | 325 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Actor < ActiveRecord::Base
has_many :characters
has_many :shows, through: :characters
def full_name
"#{self.first_name} #{self.last_name}"
end
def list_roles
roles_array = []
self.characters.all.each do |character|
roles_array << "#{character.name} - #{character.show.name}"
end
roles_array
en... | true |
e73572d52d3d580db35d11728dc66be0143098c4 | Ruby | tycardall/test1_20150414 | /ex_4_3.rb | UTF-8 | 70 | 3.21875 | 3 | [] | no_license | #ex_4_3
def multiply(a, b)
a * b
end
c = multiply(10, 13)
puts c
| true |
6a60a3ea0c838b353ed8fc86e83159dc7a4a29c6 | Ruby | gitter-badger/alphadox | /src/sexp.rb | UTF-8 | 1,451 | 2.828125 | 3 | [] | no_license | require "minitest/autorun"
require "strscan"
module Alphadox
module SExp
# A quick and dirty s-expression parser to read in KiCAD files.
def self.parse(str)
ss = StringScanner.new(str)
raise "OMG" if ss.scan(/\s*\(/).nil?
stack = [[]]
until ss.eos?
case
when ss.scan... | true |
2a13926a41a567a1cd20a6986d62563a6310967d | Ruby | Manavendu/Sparta_Project_Euler | /spec/multiple_spec.rb | UTF-8 | 214 | 2.640625 | 3 | [] | no_license | describe Multiple do
before(:all) do
@multiple = Multiple.new
end
it "should add the number which are multiple of 3 and 5" do
expect(@multiple.sum).to eq(233168)
end
end
| true |
9d1ce6d4946b26dca5f59e63cf73a6dfb18e7511 | Ruby | BDNelson123/houseAPI | /spec/models/common_spec.rb | UTF-8 | 3,777 | 2.65625 | 3 | [] | no_license | require 'spec_helper'
describe Common do
describe "format" do
it "should replace spaces with addition signs" do
phrase = Common.format("I love to play basketball")
expect(phrase).to eq("I+love+to+play+basketball")
end
it "should return the phrase" do
phrase = Common.format("ILoveToPlay... | true |
31695d40807c6c7aa303e1383ba8161f9b73fd37 | Ruby | nataliewilson66/knight_travails | /lib/knightpathfinder.rb | UTF-8 | 2,126 | 3.640625 | 4 | [] | no_license | require_relative 'poly_tree_node'
class KnightPathFinder
def initialize(position)
@root_node = PolyTreeNode.new(position)
@considered_positions = [position]
build_move_tree
end
def KnightPathFinder.valid_moves(pos)
moves = []
row, col = pos
(-2..2).each do |i|
new_row = row + i
... | true |
bb6d3acc077c04305136a0863d8e0702591ebd69 | Ruby | cjsatuforc/veneer | /veneer.rb | UTF-8 | 1,790 | 3.03125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby -wKU
require 'rubygems'
require 'rmagick'
# Usage: ruby veneer.rb filename.gcode filename.png > new.gcode
# Only works with skeinforge gcode comment markers
# This simple proof of concept expects a 100x100 pixel png and a cylinder with 100 sides
gcode_filename = ARGV.shift || "wood_texture_cup.gc... | true |
60e126b4502e7c0a8dd3b3e92d0d80773f4cbc75 | Ruby | Wolfy858/w2d3 | /poker/spec/card_spec.rb | UTF-8 | 306 | 2.640625 | 3 | [] | no_license | require 'card'
describe Card do
subject(:ace_of_spades) {Card.new(14, :spade)}
describe '#initialize' do
it 'sets up a card\'s suit' do
expect(ace_of_spades.suit).to eq(:spade)
end
it 'sets up a card\'s value' do
expect(ace_of_spades.value).to eq(14)
end
end
end
| true |
c165311063304526a2393f48c1bd73b4e8d63320 | Ruby | clanfy/cars_2.0 | /specs/engines_specs.rb | UTF-8 | 526 | 2.859375 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../engines')
class TestEngine < Minitest::Test
def setup
@regular = Engine.new(10, 10)
@turbo = Engine.new(25, 15)
@hybrid = Engine.new(10, 5)
@time_machine = Engine.new(5, -5)
end
def test_get_engine_acceleration
assert_e... | true |
e2e62e558e3834f9fd93d43b6b77a81184d82642 | Ruby | JayJayTing/TwoPlayerMathGame | /Player.rb | UTF-8 | 224 | 3.203125 | 3 | [] | no_license | class Player
def initialize(name)
@name = name
@lives = 3
@score
end
def getName
@name
end
def getUserInput
gets.chomp
end
def deductLife
@lives -= 1
end
def checkLife
@lives
end
end | true |
3005b6ac7022f199471756d85ad86f043d2bc0c7 | Ruby | davidjoliver/tic-tac-toe | /lib/brain.rb | UTF-8 | 1,107 | 3.625 | 4 | [] | no_license | # Use 'Min-Max' algorithm to score possible moves and pick the highest-scored one
class Brain
attr_accessor :player, :game, :best_move
def initialize options={}
@game = options[:game]
@computer = @game.computer_player
@player = Player.new(marker: @computer.marker == "X" ? "O" : "X")
end
def ponder... | true |
6314e6d78e12d41b9ef21a9b4f777e9b4d5246f3 | Ruby | Syncleus/Aethyr | /lib/aethyr/extensions/objects/clothing_items.rb | UTF-8 | 1,639 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | require 'aethyr/core/objects/traits/wearable'
require 'aethyr/core/objects/game_object'
class GenericClothing < GameObject
include Wearable
def initialize(*args)
super
@movable = true
info.layer = 2
end
end
class Shirt < GenericClothing
include Wearable
def initialize(*args)
super
inf... | true |
6ab9db5e4c1722efed41ee91aa4de62fbf771fdc | Ruby | nukecpower/themekit | /scripts/themekit_release/repository.rb | UTF-8 | 709 | 2.859375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'git'
require 'semverly'
# Repository is used for checking the current tag is the most recent
class Repository
GIT_DIR = File.expand_path(__FILE__ + '/../../..')
def initialize
@git = Git.open(GIT_DIR)
ensure_head_is_at_latest_version
end
def latest_version
l... | true |
1b5aa8477d3e3380dd404bd097baf1f20817078b | Ruby | amandeep1420/RB101 | /RB101/L2/rev.1/debugging_and_pry.rb | UTF-8 | 678 | 3.265625 | 3 | [] | no_license | =begin
***re-read the lesson: https://launchschool.com/lessons/a0f3cd44/assignments/e742d6***
- pry is a powerful REPL in Ruby that you can use for debugging; it stops the code wherever it's called and allows you to inspect the state of your code.
- two steps to using it:
- first, type require "pry" somewhere pr... | true |
aff717a594b3bc0bbd9c12c21eeda9949af177eb | Ruby | Hostile359/rubyLabs | /lab1/lib/main.rb | UTF-8 | 325 | 3.671875 | 4 | [] | no_license | require_relative 'converter'
class Main
def self.main
puts 'Enter temperature:'
t = gets.to_f
puts 'Enter scale 1 [C, K, F]:'
scale1 = gets.chomp
puts 'Enter scale 2 [C, K, F]:'
scale2 = gets.chomp
result = Converter.convert(t, scale1, scale2)
puts "Result: #{result}"
end
end
Main.... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.