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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6b11fc452b7391ceee681664711c526cfadfe3bc | Ruby | rmulhol/mastermind_the_first | /second_attempt/spec/command_line_display_spec.rb | UTF-8 | 3,179 | 3.5625 | 4 | [] | no_license | require 'command_line_display'
describe CommandLineDisplay do
let(:test) { described_class.new }
describe "#welcome_user" do
it "welcomes the user" do
expect { test.welcome_user }.to output("Welcome to Mastermind\n").to_stdout
end
end
describe "#explain_rules" do
it "explains the game rule... | true |
ca7a00576b216c63a4a7d18ddc1dd68b6c6ed891 | Ruby | bethqiang/psychic-potato | /app/controllers/contacts_controller.rb | UTF-8 | 1,738 | 2.703125 | 3 | [] | no_license | class ContactsController < ApplicationController
def new
# GET reqeust to /contact-us
# Show new contact form
# Every time someone pulls up our comments form, Rails will create a new
# blank contact object
# Store it in the contact variable
# @ indicates instance variable
@contact = Contac... | true |
28ff2e0bff18399dec1d9392a4185ef3031e23fa | Ruby | vkurennov/tceh_ruby | /01_ruby_intro/hello.rb | UTF-8 | 241 | 3.640625 | 4 | [] | no_license | puts "Привет, как тебя зовут?"
name = gets.chomp
puts "Какой твой год рождения?"
year = gets.to_i
puts "Привет, #{name}!"
puts "Твой примерный возраст #{2015 - year} лет"
| true |
3159a75b538589e4e86c6c2eae62151617157b93 | Ruby | lusketeer/aa-works | /w1/w1d5/TicTacToeAI/skeleton/lib/tic_tac_toe_node.rb | UTF-8 | 1,904 | 3.6875 | 4 | [] | no_license | require_relative 'tic_tac_toe'
class TicTacToeNode
attr_accessor :board, :next_mover_mark, :prev_move_pos
def initialize(board, next_mover_mark, prev_move_pos = nil)
@board, @next_mover_mark, @prev_move_pos =
board, next_mover_mark, prev_move_pos
end
def losing_node?(evaluator)
if board.over?
... | true |
23e4cf374a1a125503c986c054606e5fd2f4d9bd | Ruby | Eli1771/tic-tac-toe-rb-online-web-sp-000 | /lib/tic_tac_toe.rb | UTF-8 | 2,362 | 4.125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{b... | true |
e9fec3749119ef91135d4786fdfc8d80f22de10d | Ruby | landlessness/playing-with-fibers | /event_machine_intro/echo.rb | UTF-8 | 202 | 2.59375 | 3 | [] | no_license | # to use:
# telnet localhost 10000
require 'eventmachine'
class Echo < EM::Connection
def receive_data(data)
send_data(data)
end
end
EM.run do
EM.start_server("0.0.0.0", 10000, Echo)
end | true |
80015dc5de01c4c6c04331c2e46204bbc99b4aa5 | Ruby | palderson/tutorli | /app/models/enrolment.rb | UTF-8 | 1,674 | 2.515625 | 3 | [] | no_license | class Enrolment < ActiveRecord::Base
belongs_to :user
belongs_to :course
attr_accessor :stripe_card_token
OUR_COMMISSION = 0.2
TRANSACTION_FEE = Money.new(30)
STRIPE_COMMISSION = 0.029
def save_with_payment(is_test = false)
Rails.logger.debug "save_with_payment(#{is_test})"
price = course.price... | true |
9acb3d82371a40727eb3bae38ae132099b340dc3 | Ruby | AndyDangerous/mastermind | /test/guess_builder_test.rb | UTF-8 | 844 | 2.765625 | 3 | [] | no_license | gem 'minitest', '~> 5.2'
require 'minitest/autorun'
require 'minitest/pride'
require './lib/guess_builder'
class GuessBuilderTest < Minitest::Test
attr_reader :gb
def setup
@gb = GuessBuilder.new
Game.new(4, %w(r g b y))
end
def test_it_builds_a_valid_guess
assert gb.build('rrrr', 4)
end
... | true |
736675779ad1bf44d366a9ebf38e7ba9c9c06e05 | Ruby | jrabeck/weekend_work | /weekend_one/attr_readers.rb | UTF-8 | 608 | 4.28125 | 4 | [] | no_license | class Car
# Our car will have 2 properties:
# - color
# - make
attr_reader :color, :mileage
def initialize(color, make)
@color = color
@make = make
@mileage = calculate_mileage(50, 50)
end
def calculate_mileage(number1, number2)
"Mileage blah" + @color
end
# # attr_reader creates this method
# #... | true |
9040dc72fb613eec9ecd286159fd2deaa7be73e9 | Ruby | dbpatnode/favfest | /app/models/artist_festival.rb | UTF-8 | 770 | 2.640625 | 3 | [] | no_license | class ArtistFestival < ApplicationRecord
belongs_to :artist
belongs_to :festival
def self.search (search)
search = search.titleize
if search.empty?
@artist_fesitval = nil
else
find_festival(search)
end
end
def self.find_festival(search)
key = "%#{search}%"
@festival = Fe... | true |
6772f4316cf729d8b0a338262dd1be264f3dfcb7 | Ruby | ctdupuis/array-methods-lab-online-web-pt-090819 | /lib/array_methods.rb | UTF-8 | 309 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_include(array, element)
array.include?(element)
end
def using_sort(array)
arr = array.sort
arr
end
def using_reverse(array)
arr = array.reverse
arr
end
def using_first(array)
first = array.first
first
end
def using_last(array)
last = array.last
last
end
def using_size(array)
array.size
end
| true |
50b980127d479c886d94e40656d41cf8a9bb61e4 | Ruby | snlkumar/weightloss | /db/migrate/20110401005701_create_exercises.rb | UTF-8 | 773 | 2.6875 | 3 | [] | no_license | require 'csv'
class CreateExercises < ActiveRecord::Migration
def self.up
create_table :exercises do |t|
t.string :description, :category
t.decimal :mets, :precision => 5, :scale => 2
t.timestamps
end
csv = CSV.read(File.join(::Rails.root.to_s, 'utils', "exercise_mets.csv"))... | true |
6e94293facbe618901625197b386615fd019c9b5 | Ruby | jaintarun/appfigures | /lib/appfigures.rb | UTF-8 | 7,496 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'appfigures/version'
require 'appfigures/connection'
require 'utils/hash_extensions'
require 'date'
require 'json'
class Appfigures
attr_reader :connection
def initialize(options = {})
@connection = Appfigures::Connection.new options[:username], options[:password], options[:client_key]
end
#https... | true |
5e58fb71af417b53d40964e9f905f90f2b262546 | Ruby | JonahMoses/sales_engine | /test/items/transaction_test.rb | UTF-8 | 1,211 | 2.71875 | 3 | [] | no_license | require 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
require './lib/items/transaction'
require './lib/items/invoice'
require './lib/repos/invoice_repo'
require "./lib/sales_engine"
class TransactionTest < MiniTest::Test
attr_reader :transaction_repo,
:engine
def setup
@eng... | true |
12f7ed2d13c41539c0bf7129f1792d4796a8ab62 | Ruby | swetakumari95/Programming-Ruby | /Chapter 6/example7.rb | UTF-8 | 211 | 3.828125 | 4 | [] | no_license | #Chapter 6, More about Methods
#expanding arrays in method calls
def five(a,b,c,d,e)
"I was passed #{a}, #{b}, #{c}, #{d}, #{e}"
end
puts five(1,2,3,4,5)
puts five(1,2,3,*['a', 'b'])
puts five(*(10..14).to_a) | true |
f901d2ae37a173a595f6dd0aaca423c16c695c3d | Ruby | cjfuller/imageanalysistools | /src/main/resources/edu/stanford/cfuller/imageanalysistools/resources/common_methods.rb | UTF-8 | 4,218 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #--
# /* ***** BEGIN LICENSE BLOCK *****
# *
# * Copyright (c) 2012 Colin J. Fuller
# *
# * Permission is hereby granted, free of charge, to any person obtaining a copy
# * of this software and associated documentation files (the Software), to deal
# * in the Software without restriction, including without limi... | true |
836f81e91134accd6db71a382f6bc6c61af3fe3e | Ruby | skovachev/Ruby-on-Rails-1 | /week2/1-micro-blog/app/app.rb | UTF-8 | 708 | 2.78125 | 3 | [] | no_license | require_relative 'post'
require_relative 'tag'
require_relative 'support'
require_relative 'setupdb'
class App
def all_tags
Tag.find_all.map(&:name)
end
def all_posts
Post.find_all
end
def extract_tags(content)
content.scan(/#(\w+)/).flatten
end
def posts_for_tag(tag)
Post.find_by_tag ... | true |
5ea6f73f4c06e50d3c264b381623cac5ebfb4ecf | Ruby | pmichaeljones/learn-to-program | /roman_numeral.rb | UTF-8 | 3,533 | 3.609375 | 4 | [] | no_license | def roman_numeral(year)
roman = ""
roman << "M" * (year / 1000)
year -= (year / 1000) * 1000
if year / 100 == 0
if year / 50 == 1
roman << "L"
year -= 50
if year / 9 == 1
roman << "IX"
year -= 9
elsif year / 5 == 1
roman << "V"
year -= 5
if (year / 1 == 1) || (year ... | true |
577980b4d6c491ca77ca453eeb500ff0c0ae1db7 | Ruby | apexskier/code4cash | /ClockAngles/ClockAngles.rb | UTF-8 | 1,151 | 3.15625 | 3 | [] | no_license | DEG_PER_HOUR = (360.to_f / 12)
# puts DEG_PER_SEC
DEG_PER_MIN = (360.to_f / 60)
DEG_PER_SEC = DEG_PER_MIN
file = File.new("SampleInput.txt", "r")
lines = file.readlines
file.close
# puts lines.inspect
count = lines.shift
lines.map! do |line|
hour = line[0..1]
minute = line[3..4]
second = line[6..7]
# puts... | true |
bbd70dab83f68c1f2b9f54f5cbc25d7047aaac23 | Ruby | vowyy/BiliBuddy | /app/models/meal.rb | UTF-8 | 2,059 | 2.59375 | 3 | [] | no_license | class Meal < ApplicationRecord
belongs_to :foreigner
belongs_to :location
has_many :matches, dependent: :destroy
has_many :favors, dependent: :destroy
has_many :japanese, through: :favors
has_one :room, dependent: :destroy
NOBODY_IS_CHOSEN = 0
EXCESSIVE_ARE_CHOSEN = 3
MEAL_SAIZ_LIMITATION = 5... | true |
23454666805ca3297d59b2beb3e42b2df2eda65b | Ruby | jwworth/exercism | /ruby/affine-cipher/affine_cipher.rb | UTF-8 | 1,156 | 3.484375 | 3 | [] | no_license | require 'openssl'
class Affine
ALPHA = ('a'..'z').to_a
attr_reader :key_first, :key_last
def initialize(key_first, key_last)
raise ArgumentError if coprime?(key_first, alpha_length)
@key_first = key_first
@key_last = key_last
end
def encode(plaintext)
prepare_text(plaintext).map do |lette... | true |
26a4de29251acb46daa27fcf85de58c14ee2fc40 | Ruby | krumfola/FERR | /hw3/HW_03.rb | UTF-8 | 3,055 | 4.53125 | 5 | [] | no_license | ###############################################################################
#
# Introduction to Ruby on Rails
#
# Homework 03
#
# Purpose:
#
# Read the links below and complete the exercises in this file. This Lab
# is to help you better understand Arrays, Hashes and Loops that we
# learned in Lesson 03.
#
########... | true |
5fb85c2565e53d19f0696692944954b9f8ddaf7c | Ruby | obale/semantic_crawler | /meta_extract.rb | UTF-8 | 2,625 | 3.109375 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'open-uri'
require 'awesome_print'
require 'microdata'
module Extractor
class Extractor::HTMLParser
def extract_microdata(items)
hash = Hash.new
if items.kind_of? Array and items.first and items.first.kind_of? String
hash = items
elsif items.kind_of? Array a... | true |
15304acf7ee24c0b09b4075826f9066c2bf91ebe | Ruby | bluespheal/etapa0 | /sem_1/martes/say_hi.rb | UTF-8 | 171 | 3.53125 | 4 | [] | no_license | def say_hi(name)
if name == "Daniel"
"Welcome back"
else
"Hi, #{name}"
end
end
# Pruebas
p say_hi('Daniel') == "Welcome back"
p say_hi('Juan') == "Hi, Juan" | true |
1b9e0a506f5d3993aac7febd433c4279611e80c9 | Ruby | RenCarothers/array-equals | /lib/array_equals.rb | UTF-8 | 596 | 3.6875 | 4 | [] | no_license | def find_length(array)
x = 0
return nil if array == nil
array.each do |element|
x += 1
end
return x
end
def compare_elements(array1, array2)
x = 0
while array1[x] && array2[x]
if array1[x] != array2[x]
return false
end
x += 1
end
return true
end
def array_equals(array1, array2)... | true |
8405868bfc48d47056330e33f6d78feb8828d1e5 | Ruby | zms/ironyard_v2 | /lecture_code_notes/cosmicomics_lecture_010615.rb | UTF-8 | 1,625 | 4.46875 | 4 | [] | no_license | #require 'pry'
def has_joiner?(word1, word2)
word1[-1] == word2[0]
end
def is_anagram?(word1, word2)
word1.chars.sort == word2.chars.sort
end
def is_funny_word?(word1, word2)
is_anagram?(word1, word2) && has_joiner?(word1, word2)
end
def build_dictionary
result = Hash.new([])
File.open('english-dict.txt',... | true |
b4a79aad30b2b0ab50b2cfea2ea9bd2e6f5aa8c7 | Ruby | shota27182/id-shukatsu | /app/models/concerns/active_model/enum.rb | UTF-8 | 2,086 | 2.625 | 3 | [] | no_license | module ActiveModel
module Enum
extend ActiveSupport::Concern
module ClassMethods
def enum(definitions)
raise ArgumentError, 'enum attribute: { key: value, key, value, ...} の形式で指定してください' unless valid?(definitions)
attribute = definitions.keys.first
values = definitions.values.fi... | true |
d8fd565433a928f7c669de3276bda289049840f5 | Ruby | mtvillwock/RailsCodingChallenge | /lib/cuboid.rb | UTF-8 | 2,313 | 3.5 | 4 | [
"MIT"
] | permissive | class Point
attr_accessor :x, :y, :z
def initialize(coordinates)
@x = coordinates[:x]
@y = coordinates[:y]
@z = coordinates[:z]
end
end
class Cuboid
attr_reader :origin, :vertices, :length, :width, :height
def initialize(dimensions)
@origin = dimensions[:origin] #bottom, left, front vertex... | true |
6351550bd59b6bdf81acc684164a297972fb3879 | Ruby | bettymakes/data_visualization_pokemon | /get_poketype.rb | UTF-8 | 4,414 | 3.046875 | 3 | [] | no_license | require 'nokogiri'
# gem that allows you to download the web page so we can parse it
# require 'open-uri' ... removed open uri because we are no longer scraping off of a website
# url variable set to web page we are parsing/scraping
# url = "http://pokemondb.net/pokedex/national"
file = 'pokemon-list.html' #d... | true |
78183a4adddc8113fa06094c2fb7f53a968e43b4 | Ruby | reduviidae/module-one-holiday-project-dumbo-web-121018 | /seeding/sentiment/google_sentiment.rb | UTF-8 | 1,127 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative '../../config/environment'
# Imports the Google Cloud client library
require "google/cloud/language"
def analyze_assign_sentiment
Quote.all.each do |quote|
# Instantiates a client
language = Google::Cloud::Language.new
# Detects the sentiment of the text
response = language.analyze_sentim... | true |
bb8d406edce58096fe53e57796138d85dd7f43ff | Ruby | shu0115/receibo | /vendor/bundler/ruby/1.9.1/gems/heroku-2.15.1/lib/heroku/command/ps.rb | UTF-8 | 3,425 | 2.703125 | 3 | [
"MIT"
] | permissive | require "heroku/command/base"
# manage processes (dynos, workers)
#
class Heroku::Command::Ps < Heroku::Command::Base
# ps:dynos [QTY]
#
# scale to QTY web processes
#
# if QTY is not specified, display the number of web processes currently running
#
def dynos
app = extract_app
if dynos = args.s... | true |
77f9efe4bb9a3aea811bff458bde98a82fcec2db | Ruby | octonion/tennis | /ita/scrapers/ita_league_menus.rb | UTF-8 | 1,519 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'csv'
require 'mechanize'
agent = Mechanize.new{ |agent| agent.history.max_size=0 }
agent.user_agent = 'Mozilla/5.0'
menus = Array.new
conferences = CSV.open("csv/ita_conference.csv", "w")
conferences << ["league_id", "conference_id", "conference_name"]
teams = CSV.open("csv/ita_team.cs... | true |
22388a7eadefc00ab709109f47530b5b5b719527 | Ruby | nigel-lowry/the_ray_tracer_challenge | /lib/intersection.rb | UTF-8 | 285 | 3.046875 | 3 | [] | no_license | class Intersection
include Comparable
attr_reader :t, :object
def initialize t, object
@t, @object = t, object
freeze
end
def <=>(other)
@t <=> other.t
end
def ==(other)
self.class == other.class and @t == other.t and @object == other.object
end
end | true |
c46c8fd8d53b96ca64ab78694e844b2d003a54ea | Ruby | seosgithub/threadsafe-hiredis-rb | /test/threadsafe-test.rb | UTF-8 | 903 | 2.8125 | 3 | [
"BSD-3-Clause"
] | permissive | require '../lib/hiredis.rb'
require 'hiredis'
require 'redis'
@conn = Hiredis::ThreadSafeConnection.new
@conn.connect("127.0.0.1", 6379)
@conn2 = Redis.new
$stderr.puts "Could not connect" unless @conn
def push_data
Thread.new do
begin
key = rand(100000000000)
1000.times do |i|
@conn.writ... | true |
31b4e61262161b153947bb813b04c7c59e029235 | Ruby | tbierwirth/little_shop | /app/models/cart.rb | UTF-8 | 487 | 3.25 | 3 | [] | no_license | class Cart
attr_reader :contents
def initialize(contents)
if contents
@contents = contents
@contents.default = 0
else
@contents = Hash.new(0)
end
end
def total
@contents.values.sum
end
def add_item(item_id)
@contents[item_id.to_s] += 1
end
def remove_item(item_i... | true |
6d871621907e4bf35347570610b3fd9aee1b069b | Ruby | Pensive1881/Learn_Ruby | /15_in_words.rb | UTF-8 | 1,689 | 3.90625 | 4 | [] | no_license | class Fixnum
def in_words
num = self
answer = ""
return "zero" if num == 0
if num > 999999
million = num / 1000000
num -= million * 1000000
answer << converter(million) << "million "
end
if num > 999
thousand = num / 1000
num -= thousand * 1000
answer << c... | true |
a381c42497bc8fe5520c78e81003f3daa01d2a6d | Ruby | awslabs/cloud-templates-ruby | /lib/aws/templates/utils/guarded.rb | UTF-8 | 811 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | require 'aws/templates/utils'
module Aws
module Templates
module Utils
##
# Remember Alan Turing's halting problem and don't believe in miracles. The method will
# only work with parameters because they are supposed to be pure unmodifying functions.
# Hence we can terminate if a parameter... | true |
e28f38dc017a11fa561c9f8c57d28e9afa90efb6 | Ruby | jalbersh/Sept14CodeChallange | /acceptance/spec/helpers/LOWER_UNDERSCORE_NAME_server.rb | UTF-8 | 1,770 | 2.53125 | 3 | [] | no_license | require_relative './retry_for'
class APPLICATION_NAMEServer
attr_reader :app_port
def initialize(port, simulator_port)
@app_port = port
@simulator_port = simulator_port
end
def start
return if app_is_running?
unless artifact_exists?
puts ''
puts '<'*80
puts ''
puts "N... | true |
e557d006d79108d2f9b0a9be2917402c87df991c | Ruby | maye-gallardo/QUADRITOS | /spec/line_spec.rb | UTF-8 | 974 | 3.015625 | 3 | [] | no_license | require './lib/line'
describe "Pruebas de la clase Line" do
before :each do |single|
@line = Line.new(10, 10, 20, 20)
end
it "deberia crearse una linea con su posicion x1 igual '10'" do
expect(@line.getPosX1()).to eq 10
end
it "deberia crearse una linea con su posicion x2 igual '... | true |
7fa37698b681a1f98a674a98f969f8e0a1cee9dc | Ruby | surfer8137/KataBankOCR | /lib/entryparser.rb | UTF-8 | 1,297 | 3.734375 | 4 | [] | no_license | require 'digit'
class EntryParser
LINES = 4
CHARS_PER_DIGIT = 9
CHARS_PER_DIGIT_PER_LINE = 3
NUMBER_OF_DIGITS = 9
class << self
def parse(input)
result = ''
NUMBER_OF_DIGITS.times do |digit_position|
digit_chars = parse_digit(input, digit_position)
result << Digit.parse(digit... | true |
cbaaca9a2252992d282ab65f99e8d841aa582eef | Ruby | luciaprietosantamaria/Bioinformatic-programming-challenges | /Assignment2/Protein.rb | UTF-8 | 4,918 | 3.109375 | 3 | [] | no_license | #-----------------------------------------------------
# Bioinformatic programming challenges
# Assignment2: PROTEIN Object
# author: Lucía Prieto Santamaría
#-----------------------------------------------------
require 'net/http'
require 'json'
require './PPI.rb'
class Protein
attr_accessor :prot_id # UniProt... | true |
d2f5f90f8c9958e23deea9302d0ab766f4a45d2f | Ruby | itgsod-simon-lundgren/bildgen | /filer/funktiontest.rb | UTF-8 | 562 | 2.703125 | 3 | [] | no_license | require 'devil'
# class Pictures
hej = []
files = Dir.glob('storabilder/*')
files = files.map { |file| [file.count("/"), file] }
files = files.sort.map { |file| file[1] }
files.each do |base|
hej << File.basename(base)
end
puts hej
hej.each do |file|
Dir.chdir('./storabilder')
puts Dir.getwd
Devil.with_image(file)... | true |
ca212c0830aedd68452a348a5e5be1b121e7be39 | Ruby | Enocruz/SWArchitectureClass | /decorator/src/coffee_test.rb | UTF-8 | 1,382 | 3.171875 | 3 | [] | no_license | # The source code contained in this file is used to
# test the coffee.rb program.
# Adapter Pattern
# Date: 08-March-2018
# Authors:
# A01374648 Mario Lagunes Nava
# A01375640 Brandon Alain Cruz Ruiz
# File: coffee_test.rb
# Adding the namespaces require to run the file
require 'minitest/autorun'
... | true |
11e35fd117ca9a3e339414d1f4f9e33628ab8e70 | Ruby | maxximus87/Game | /console_human.rb | UTF-8 | 278 | 3.671875 | 4 | [] | no_license | class Human
attr_reader :marker
def initialize(marker)
@marker = marker
end
def get_move(board)
puts "Make a move"
move = gets.chomp.to_i - 1
if board[move] == ""
move
else
puts "Spot already taken."
get_move(board)
end
end
end | true |
be335536201fcea10e74085994d5e68959efdf48 | Ruby | kokoko313/codewars | /fizzbuzz.rb | UTF-8 | 295 | 3.609375 | 4 | [] | no_license | puts (1..20).map {|i|
f = i % 3 == 0 ? 'Fizz' : nil
b = i % 5 == 0 ? 'Buzz' : nil
f || b ? "#{ f }#{ b }" : i
}
(1..100).each do |num|
message = ""
message << "fizz" if num%3 == 0
message << "buzz" if num%5 == 0
message << num.to_s if message.length == 0
puts message
end | true |
06a30e3b023704e5005796d3bd512a629224b5f0 | Ruby | dmn88mia/ls_exercises | /101_109_small_problems/easy_5/aplabet_nums.rb | UTF-8 | 2,346 | 4.5 | 4 | [] | no_license | # Understand the problem :
# Write a method that takes an Array of Integers between 0 and 19, and returns an Array
# of those Integers sorted based on the English words for each number:
# Set up your test cases
# alphabetic_number_sort((0..19).to_a) == [
# 8, 18, 11, 15, 5, 4, 14, 9, 19, 1, 7, 17,
# 6, 16, 10, 1... | true |
826e5599e3ff56cb39e6715ebfeca8bd34b2ac6a | Ruby | syntacticsugar/Lovespell | /alt_animal_bird.rb | UTF-8 | 742 | 3.609375 | 4 | [] | no_license | class Brood
NAMES = %w( feathers quill falcon aerie nest eggs smokey skittles cereal merlin).map &:capitalize
def initialize(n)
@names = NAMES.sort {rand - 0.5}.take n
end
def hatch
if @names.empty?
raise EmptyNestException
else
n = @names.shift
f = rand 10
Bird.new n, f
end
... | true |
dafded257f52c2f53d871243cad01560391e3d5f | Ruby | andynu/rfk | /impression_log_to_scikitlearn_tsvs.rb | UTF-8 | 2,447 | 3.03125 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
require 'chronic'
require 'set'
# Convert impression log into linear set of tag impressions
#
# outputs env_details.tsv:
# song label value impression
#
env = {}
File.open('env_detail.tsv','w') do |f|
File.open('data/impression.log').each_with_index do |line,i|
time,tag,*rest = line.str... | true |
262f49dae146e4f3f5932e7e80e74d97fd9b497b | Ruby | loantranuet/BTVN_Ruby-Intro | /hw-ruby-intro-master/hw-ruby-intro-master/lib/ruby_intro.rb | UTF-8 | 2,239 | 4.28125 | 4 | [] | no_license | # Part 1
# Define a method sum(array) that takes an array of integers as an argument and returns the sum of its elements.
def sum (arr)
s=0
arr.each{|a| s+=a}
return s
end
# Define a method max_2_sum(array) which takes an array of integers as an argument and returns the sum of its two largest elements.
de... | true |
3c3b92a7ab5c0c531496a4ad8ed80ff837a7eb82 | Ruby | dancernerd32/my-first-repository | /hours_in_a_year.rb | UTF-8 | 212 | 3.734375 | 4 | [] | no_license | puts "What year is it?"
year=gets.to_i
if year%4==0 && year%100!=0 || year%400==0
hours=366*24
puts "366 days times 24 hours per day"
else
hours=365*24
end
puts "There are " + hours.to_s + " hours in this year."
| true |
eefa3f2eb2679ef1b2c8ea0369ba130de590b166 | Ruby | prichard191/ruby-enumerables-introduction-to-map-and-reduce-lab-dumbo-web-120919 | /lib/my_code.rb | UTF-8 | 1,200 | 3.421875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def map_to_negativize(source_array)
new_arry = []
i = 0
while i < source_array.length do
new_arry.push( source_array[i] * -1 )
i += 1
end
return new_arry
end
def map_to_no_change(source_array)
some_arry = []
i = 0
while i < source_array.length do
some_arry.push( source_array[i] )
i += 1... | true |
1f6c60a7699297465b2c899358463da89ab79676 | Ruby | senseizp92/notepad | /task.rb | UTF-8 | 871 | 2.859375 | 3 | [] | no_license |
# Подключим встроенный в руби класс Date для работы с датами
require 'date'
# Класс Задача, разновидность базового класса "Запись"
class Task < Post
def initialize
super # вызываем конструктор родителя
# потом инициализируем специфичное для Задачи поле - дедлайн
@due_date = Time.now
end
# Этот ме... | true |
1f564f26364af08552570a887be0bb5aff12021e | Ruby | repl-electric/dl-_-lb | /rescue/support/midi.rb | UTF-8 | 7,738 | 2.546875 | 3 | [] | no_license | def state()
$daw_state ||= {}
end
def warm
alive pad: 1 , apeg: 1, bass: 1, piano: 1, vocal: 1, kick: 1
[:c3, :cs3, :d3, :ds3, :e3, :f3, :fs3, :g3, :gs3, :a3, :as3, :b3,
:c4, :cs4, :d4, :ds4, :e4, :f4, :fs4, :g4, :gs4, :a4, :as4, :b4,
:c5, :cs5, :d5, :ds5, :e5, :f5, :fs5, :g5, :gs5, :a5, :as5, :b5,
].e... | true |
5f91a29b32a9330ba81161519008afbdb2ca8860 | Ruby | codegorilla/lang2 | /CharacterLiteral.rb | UTF-8 | 287 | 2.625 | 3 | [
"MIT"
] | permissive | require 'erb'
class CharacterLiteral
attr_reader :value
def initialize (value)
@value = value
end
def render ()
file = File.read("view/character_literal.c.erb")
template = ERB.new(file, nil, trim_mode=">", eoutvar='_sub01')
template.result(binding)
end
end
| true |
8f58b322360b2e980140325fafd6d3472a378a2c | Ruby | Alex-ray/craigslist_jr | /db/seeds.rb | UTF-8 | 636 | 2.734375 | 3 | [] | no_license | require 'faker'
def seed_categories
categories = ["Hover Cars", "Spaceship",
"Flying Carpets", "Jet Packs",
"Google Glasses", "Doo Hickeys"]
categories.each do |category|
Category.create(name: category)
end
end
def seed_posts
categories = Category.all
100.times do
... | true |
96fd404d0e46be13c0214bdb721727f0a0296cca | Ruby | oozywaters/thinknetika-lessons | /Lesson-02/05_date.rb | UTF-8 | 780 | 3.953125 | 4 | [] | no_license | puts "Введите число (день):"
day = gets.chomp.to_i
puts "Введите порядковый номер месяца:"
month = gets.chomp.to_i - 1
puts "Введите год:"
year = gets.chomp.to_i
def leap_year?(year)
(year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)
end
days_count = 0
months_days = [31, (leap_year?(year) ? 29 : 28), 31, ... | true |
b6a732a49885f0b0ecf8cfd60c82b5a0b059f4a6 | Ruby | mathewdbutton/exercism-exercises | /ruby/difference-of-squares/difference_of_squares.rb | UTF-8 | 352 | 2.953125 | 3 | [] | no_license | class Squares
POWER = 2
def initialize(natural_number)
@natural_number = natural_number
end
def square_of_sum
(1..@natural_number).sum ** POWER
end
def sum_of_squares
(1..@natural_number).map { |n| n ** POWER }.sum
end
def difference
square_of_sum - sum_of_squares
end
end
modul... | true |
a230a6741998d802fca145fd9770dcb7cdd0c5a6 | Ruby | sis-berkeley-edu/calcentral | /app/models/hub_edos/student_api/v2/student/student_attribute.rb | UTF-8 | 2,050 | 2.828125 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"ECL-2.0"
] | permissive | module HubEdos
module StudentApi
module V2
module Student
# A Student Attribute is a free form characteristic assigned to the student via various processes.
class StudentAttribute
def initialize(data)
@data = data || {}
end
# a short descriptor rep... | true |
f9622b1f0cd4f723e669df099797efec2b19a092 | Ruby | csuhta/environment | /bin/random | UTF-8 | 2,876 | 3.28125 | 3 | [
"Unlicense"
] | permissive | #!/usr/bin/env ruby
# encoding: utf-8
# Generates random values
# Usage: random [-uxah] [--uuid] [--hexadecimal] [--alphanumeric] [--help] [length]
# -x, --hexadecimal Return a hexadecimal number
# -a, --alphanumeric Return alphanumeric characters (default)
# -u, --uuid ... | true |
0e8f953af2da53169cd3314b7aa511b7dbfdf541 | Ruby | emmiehayes/credit_check | /test/credit_check_test.rb | UTF-8 | 2,108 | 3.15625 | 3 | [] | no_license | require 'minitest/autorun'
require "minitest/pride"
require './lib/credit_check'
class CreditCheckTest < Minitest::Test
def test_it_can_convert_integer_to_reversed_array
cc = CreditCheck.new
expected = [3, 4, 5, 0, 5, 2, 7, 7, 4, 5, 3, 7, 9, 2, 9, 4]
assert_equal expected, cc.card_number_to_reversed_arr... | true |
a482437b2027e84c41fad3138c8fc916cf507445 | Ruby | michaelrizzo2/Ruby-Development | /array_iterator.rb | UTF-8 | 344 | 3.921875 | 4 | [] | no_license | #!/usr/bin/ruby
#This will iterate through an array using an until loop and while loop
array=[1,2,3,4,5]
#This will set the iterator index for the array
index=0
#while index<array.length
# puts "array entry #{index} is #{array[index]}"
# index+=1
#end
until index==array.length
puts "array entry #{index} is #{array... | true |
255a4eb237e173e2ba4cea9e6fef9034f2f8caaa | Ruby | esmith2078/launch_school | /ruby_basics/user_input/print_something2.rb | UTF-8 | 514 | 4.125 | 4 | [] | no_license | # print_something2.rb
loop do
puts '>> Do you want me to print something? (y/n)'
choice = gets.chomp
if choice.upcase.eql? "Y"
puts 'something'
elsif choice.upcase.eql? "N"
else
puts 'Incorrect selection, try again'
end
break
end
# Solution version
=begin
choice = nil
loop do
puts '>> Do y... | true |
aa91c2f9c28388ab7edb5986947e4573a482f531 | Ruby | mrrusof/algorithms | /paint-house/ruby/main.rb | UTF-8 | 1,040 | 4.0625 | 4 | [] | no_license | #!/usr/bin/env ruby
=begin
There are a row of n houses, each house can be painted with one of the
three colors: red, blue or green. The cost of painting each house with
a certain color is different. You have to paint all the houses such
that no two adjacent houses have the same color.
The cost of painting each house... | true |
c8550fa8791ba71ea87368b784d47024b92f9d50 | Ruby | marcbobson2/supplement | /quiz1int/problem4.rb | UTF-8 | 368 | 4.25 | 4 | [] | no_license | numbers = [1, 2, 3, 4]
numbers.each do |number|
p number
numbers.shift(1)
end
#first will print out 1
#next will reduce array to [2,3,4]
#question: how does each work
# since each calls the block for each element, it should print out 2, then 3, then 4
numbers = [1, 2, 3, 4]
numbers.each do |number|
p number
n... | true |
e97a7f508902691c69a2f3beeb2648d7d7b6e73a | Ruby | mbj/formitas | /lib/formitas/binding.rb | UTF-8 | 2,446 | 2.859375 | 3 | [
"MIT"
] | permissive | module Formitas
# Abstract base class for field with value
class Binding
include Adamantium::Flat, AbstractType
abstract_method :html_value
abstract_method :domain_value
# Return field
#
# @return [Field]
#
# @api private
#
attr_reader :field
private
# Initialize ... | true |
16ba790ae6f5006798aa0c3dd80ee1ea1d50dc54 | Ruby | vzasade/myscrpts | /explode.rb | UTF-8 | 2,048 | 2.890625 | 3 | [] | no_license | if __FILE__ == $0
# TODO Generated stub
end
def suppress_warnings
original_verbosity = $VERBOSE
$VERBOSE = nil
result = yield
$VERBOSE = original_verbosity
return result
end
require 'rubygems'
require 'zip/zip'
suppress_warnings{require 'FileUtils'}
require 'find'
def unzip_file (file, destina... | true |
3a475e5590d9deb0a380cc4137a2b7d4e537493b | Ruby | li-thy-um/leetcode | /4-median-of-two-sorted-arrays.rb | UTF-8 | 3,208 | 3.34375 | 3 | [] | no_license | # @param {Integer[]} nums1 (Array A)
# @param {Integer[]} nums2 (Array B)
# @return {Float}
def find_median_sorted_arrays(nums1, nums2)
raise "Empty inputs" if nums1.size + nums2.size == 0
return nums2.sorted_median if nums1.size == 0
return nums1.sorted_median if nums2.size == 0
solve(nums1, nums2, 0, nums1.si... | true |
1fb4702da3f67c4762704860ddd17df2fa82362a | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/leap/ba18aff13a8645178373b3ce10a9344b.rb | UTF-8 | 410 | 3.59375 | 4 | [] | no_license | module Year
extend self
def leap?(year)
return fourth_year?(year) if div_by?(year, 400)
return fourth_year_of_a_non_century?(year)
end
private
def fourth_year_of_a_non_century?(year)
fourth_year?(year) && !century?(year)
end
def century?(year)
div_by?(year, 100)
end
def fourth_year... | true |
7085bb5ed17ad3214678faa0ed0bf16986dea173 | Ruby | tdooner/advent-code | /2020/14/process.rb | UTF-8 | 1,545 | 3.5 | 4 | [] | no_license | require 'pry'
input = $<.map(&:strip)
def solve(input)
bitmask = nil
mem = {}
input.map do |line|
cmd, value = line.split(' = ')
if cmd == 'mask'
bitmask = value.reverse
else
mem_id = cmd[4..-2]
binary = value.to_i.to_s(2).each_char.map(&:to_i).reverse
masked_value = bitmask... | true |
5b1266434fc0e2fa4947f7d19a85c9cad9be8dd0 | Ruby | Lodi2244/THP-semaine-0 | /exo_19.rb | UTF-8 | 251 | 2.953125 | 3 | [] | no_license | my_array = []
0.upto(50) do |i|
i += 1
if i < 10
my_array << "Tite.Lodi.0#{i}@email.com"
else
my_array << "Tite.Lodi.#{i}@email.com"
end
end
for i in 0..my_array.size
if i % 2 != 0
break if i == 50
puts my_array[i]
end
end
| true |
8093c87b6d66c6a10b6aaa32d6227290d7e18279 | Ruby | Capncavedan/Powerball-numbers | /lib/powerball_html_grabber.rb | UTF-8 | 364 | 2.65625 | 3 | [] | no_license | require 'open-uri'
class PowerballHtmlGrabber
def html
URI.parse(url).read
end
private
def end_date
Date.parse("1 November 1997").strftime("%m/%d/%Y")
end
def start_date
Date.today.strftime("%m/%d/%Y")
end
def url
"http://www.powerball.com/powerball/pb_nbr_history.asp?startDate=#{... | true |
24172346c81fc7e7e985bbdc41885ee155c366e9 | Ruby | ElvinGarcia/my_find_code_along-v-000 | /lib/my_find.rb | UTF-8 | 240 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def my_find(collection)
i=0
while i < collection.length
return collection[i] if yield(collection[i])
i+=1
end
end
collection = (1..100).to_a
my_find(collection) do |obj|
obj % 3 == 0 && obj % 5 == 0
end | true |
133d6bee677a2297acd944d34ae81e53ce1a76f4 | Ruby | alvarezleonardo/kleer_generala | /app.rb | UTF-8 | 1,012 | 2.546875 | 3 | [] | no_license | require 'sinatra'
require './lib/Generala.rb'
get '/' do
@@generala = Generala.new
@images = []
erb :home
end
post '/tirardados' do
@@generala.tirarDados
@images = ["","","","",""]
@index = 0
@@generala.getDados.each do |dado|
@images[@index] = "<img src='./images/dado"+dado.to_s+".png'/>"
@i... | true |
9897bf95e6eb1e5076aca5e9d010ac12f046d170 | Ruby | cmezouar/thpw1_ruby_loops | /lib/03_stairway.rb | UTF-8 | 1,576 | 4.1875 | 4 | [] | no_license | def game_setup
stairway=[]
count=0
11.times do
stairway.push(count)
count=count+1
end
return stairway
end
def roll_dice
n= 1+rand(6)
puts n
return n
end
def climb_stairs(position,stairway)
new_position=position+1
position=stairway[new_position]
if positio... | true |
345131734abf11160e996011ef4622d2c566ad5c | Ruby | vasipetrova/blog | /app/models/user.rb | UTF-8 | 1,760 | 2.859375 | 3 | [] | no_license | class User < ActiveRecord::Base
has_many :posts
has_many :comments
attr_accessor :password
#before you save the password encrypt it BCrypt
before_save :encrypt_password
#validate that the password isn't blank
validates_confirmation_of :password
# The username, password and email cannot be blank when the u... | true |
05cb58ecc915adc70e2ede35490b892850b94a57 | Ruby | layornos/7lan7wks | /Ruby/regex_file.rb | UTF-8 | 351 | 2.671875 | 3 | [] | no_license | if RUBY_VERSION =~ /2.3/ # assuming you're running Ruby ~1.9
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
filename = "example.txt"
text = File.open(filename).read
linenumber = 1
text.each_line do |line|
if line =~ /ü(.*)ö(.*)(ä.*)/
puts linenumber.to_s + ": " + li... | true |
205e75a76eb42a1b07db255907d18aa74ea52681 | Ruby | dflourusso/curso-programacao | /algoritmos/ruby/sintaxe/palavras_reservadas.rb | UTF-8 | 6,078 | 3.5625 | 4 | [] | no_license | =begin ordem alfabética
BEGIN Code, enclosed in {}, to run before the program runs.
END Code, enclosed in {}, to run when the program ends.
alias Cria um apelido para um método, operador ou variável global
and Operador lógico, mesmo que &&, mas com precedência menor
begin Begins a code block or grou... | true |
37fcd4b25f20683f6d06678ab232ab91638856ed | Ruby | guidance-guarantee-programme/reporting | /app/view_models/costs/items.rb | UTF-8 | 803 | 2.78125 | 3 | [] | no_license | module Costs
class Items
attr_reader :year_months
def initialize(year_months:)
@year_months = year_months
end
def all
@all ||= begin
items = CostItem.current | CostItem.during_months(@year_months)
items = items.sort_by { |cost_item| [cost_item.cost_group, cost_item.name] ... | true |
e41bebe637d7670306d73c326ae33dbc58664ea3 | Ruby | menyhertfatyol/learning_rspec | /customer.rb | UTF-8 | 245 | 2.859375 | 3 | [] | no_license | class Customer
def initialize(opts)
@discounts = opts[:discounts]
end
def has_discount_for?(product_code)
@discounts.has_key? product_code
end
def discount_amount_for(product_code)
@discounts[product_code] || 0
end
end
| true |
ad1af6595c29326bdf060b52202327c840206db5 | Ruby | cconstantine/lemming | /lib/lemming.rb | UTF-8 | 1,681 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'benchmark'
require 'timeout'
require 'thread'
require 'pty'
require 'open3'
require 'json'
require File.join(File.dirname(__FILE__), 'result_set.rb')
require File.join(File.dirname(__FILE__), 'client')
module Lemming
class Lemming
attr_accessor :delay, :tick, :total_time, :results
... | true |
a7a22d7b1276e6a0f4f8ad2d09ccc475dfb17adc | Ruby | rohit-mathew/ruby-ds-algo | /Algorithms/sort.rb | UTF-8 | 939 | 4.21875 | 4 | [] | no_license | # Merge Sort requires O n * log n time and O (n) space
# Merges two already sorted arrays
def merge(array1, array2)
ptr1 = 0
ptr2 = 0
high1 = array1.length - 1
high2 = array2.length - 1
array_final = []
while (ptr1 <= high1) && (ptr2 <= high2) do
if (array1[ptr1] < array2[ptr2])
array_final <... | true |
3ddb31870ec6da4906ae7b328b407472b1fe6a0f | Ruby | fentontaylor/sweater-weather | /app/facades/forecast_facade.rb | UTF-8 | 1,041 | 2.859375 | 3 | [] | no_license | class ForecastFacade
attr_reader :id, :type
def initialize(location)
@location = location
@id = nil
@type = 'forecast'
end
def location_info
geolocation_decorator.location_info
end
def summary
forecast_decorator.summary
end
def current_forecast
forecast_decorator.current_fore... | true |
1e7bace2b8de1fa24629e0612594d838876c2624 | Ruby | kaspernj/wref | /lib/wref/implementations/id_class_unique.rb | UTF-8 | 1,137 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | class Wref::Implementations::IdClassUnique
def initialize(object)
@id = object.__id__
@class_name = object.class.name.to_sym
ObjectSpace.define_finalizer(object, method(:destroy))
@unique_id = object.__wref_unique_id__ if object.respond_to?(:__wref_unique_id__)
end
def get!
object = get
r... | true |
e5f0fcae321629acfd227b21c73fe22bbfd8ec70 | Ruby | Cyan101/code-examples | /daily-programmer/#317/collatz_tag_system.rb | UTF-8 | 554 | 3.984375 | 4 | [
"MIT"
] | permissive | #[2017-05-29] Challenge #317 [Easy] Collatz Tag System
#https://www.reddit.com/r/dailyprogrammer/comments/6e08v6/20170529_challenge_317_easy_collatz_tag_system/
def collatz(tag)
tag_keys = %w(a b c)
tag_system = %w(bc a aaa)
while tag.length > 1
case tag.chr
when tag_keys[0]
tag = ta... | true |
f90c114df3345270a78a9f89df0432184d41fdae | Ruby | ash106/rwc | /app/services/kml_parser.rb | UTF-8 | 996 | 2.859375 | 3 | [] | no_license | require 'open-uri'
class KmlParser
def initialize(id, model_name)
@id = id
@model_name = model_name.constantize
end
def parse_polygon
model = get_model
doc = open_doc(model)
coordinates_array = parse_coordinates(doc.at_css("polygon coordinates").text)
polygon =
{
type: "Po... | true |
56ca62a3ec920ef11b30284a7dffaf51593fd6b6 | Ruby | govfollower/repfinder | /app/services/rep_finders/by_state_district.rb | UTF-8 | 729 | 2.546875 | 3 | [] | no_license | require 'json'
module RepFinders
class ByStateDistrict
def initialize (abbr, district_no)
@state = State.find_by(abbr: abbr)
@district = District.find_by(state_id: @state.id, number: district_no.to_i) if @state.present?
end
def perform
return false unless @district
house_rep = H... | true |
33e5a08c53088975e8ddb9c8514da3a603ac6c80 | Ruby | VSuhas/Ruby-exercise-Suhas-V | /eleven.rb | UTF-8 | 806 | 3.953125 | 4 | [] | no_license | puts " 1 : adddition, 2 : Subtraction , 3: Multiplication, 4 : Division "
puts "Enter the choice number"
ch=gets.chomp
case ch
when "1"
puts "enter two numbers"
puts "enter first number"
a=gets.chomp
a1=a.to_f
puts "enter Second number"
b=gets.chomp
b1=b.to_f
c = a1 + b1
puts c
when "2"
puts "enter two nu... | true |
aef72c5c2ad7b28cc9877e754b40e034be64a85e | Ruby | sendgrid/geo_location | /lib/geo_location/countries.rb | UTF-8 | 807 | 2.859375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module GeoLocation
class << self
def country(country_code)
return nil if GeoLocation::countries.empty?
GeoLocation::countries[country_code.to_sym]
end
def build_countries
if GeoLocation::countries.empty?
data = {}
file = File.join(File.dirname(__FILE... | true |
ae3b916c98d9c37fa61b5ccfdcbe1e2329f4fe87 | Ruby | ilya-burinskiy/Ruby | /Railway/console_interface.rb | UTF-8 | 1,266 | 3.40625 | 3 | [] | no_license | # frozen_string_literal: true
class ConsoleInterface
def show_instructions(instructions)
instructions.each do |instruction|
puts instruction
end
end
def read_command
print '>>> '
gets.to_i
end
def read_station_name
print 'Enter station name: '
station_name = gets.chomp
end
... | true |
2538dcb3342eb45650e9c94604f3afea484fcaca | Ruby | patrickdavey/AoC | /2015/day19/molecule_calibrator.rb | UTF-8 | 545 | 2.65625 | 3 | [] | no_license | require 'set'
class MoleculeCalibrator
def initialize(initial_molecule:, replacements:)
@initial_molecule = initial_molecule.freeze
@replacements = replacements
@combinations = Set.new
end
def distinct_molecules
replacements.each do |replacement|
initial_molecule.clone.gsub(/#{replacement.... | true |
72f587a809e7b58b9de22a3a4c7e5ef83c316025 | Ruby | mindpin/short-comment-service | /app/models/post.rb | UTF-8 | 712 | 2.515625 | 3 | [] | no_license | class Post
include Mongoid::Document
include Mongoid::Timestamps
field :url, type: String
has_many :comments, :order => :votes_count.desc
has_many :votes
def self.get(url)
url = url.split(/#|\?/).first
Post.find_or_create_by(url: url)
end
def has_comment?(user_id)
self.comments.where(:... | true |
550f657ea585e4215031d86581831b9011b834f6 | Ruby | JordanStafford/Ruby | /Ruby Practice Continued/Arrays/acessing_array-elements.rb | UTF-8 | 638 | 4.4375 | 4 | [] | no_license | sharks = ["Hammerhead", "Great White", "Tiger"]
sharks.length #will find how many elemnents there are
print sharks.index("Tiger") #will find out what index the value is in the array
print sharks.index[-1] # will get the last element of the array
puts sharks.first #will get the first element
puts sharks.last #will ge... | true |
d48c47a8635a1465c29d05982d5716554c329759 | Ruby | hussyvel/ruby | /programas_diversos/lacos.rb | UTF-8 | 307 | 3.046875 | 3 | [] | no_license | # frozen_string_literal: true
x = 1
until x == 10
puts x
x += 1
end
# valor = 1
# loop do
# puts valor
# valor += 1
# break if valor <= 10
# end
# valor = 1
# for a in 4..25 do
# puts a
# a += 1
# end
# a = 2
# while a <= 10
# puts a
# a += 1
# end
| true |
32582d3b69b3a9f7bbda713f40c37637acd330dc | Ruby | AELSchauer/turing-headcount | /test/csv_extractor_test.rb | UTF-8 | 11,661 | 2.71875 | 3 | [] | no_license | require './test/test_helper'
require './lib/csv_extractor'
class CSVExtractorTest < Minitest::Test
def test_create
extractor = setup
expected_data = {
:enrollment=>{},
:statewide_test=>{},
:economic_profile=>{}
}
assert_equal expected_data, extractor.districts_hashes
en... | true |
f563bdfda6f39aea0f4eea2e0083d523f8b69fce | Ruby | tarasdemyanets/LinkUp-practice | /02_calculator/calculator.rb | UTF-8 | 272 | 3.171875 | 3 | [] | no_license | def add(a,b)
a+b
end
def subtract(a,b)
a-b
end
def sum(a)
a.sum
end
def multiply(a,b)
a*b
end
def power(a,b)
a**b
end
def factorial(n)
if n<0
return nil
end
if n ==0
1
end
res=1
while n>0
res=res*n
n-=1
end
return res
end
| true |
e3b9a98003eb40d1366700d27d9256e71a70c7ed | Ruby | gnfisher/sudoku_puzzle_validator | /spec/sudoku_puzzle_spec.rb | UTF-8 | 1,366 | 3.109375 | 3 | [] | no_license | require_relative "../lib/sudoku_puzzle"
describe SudokuPuzzle do
describe "#rows" do
it "returns an array of rows from puzzle" do
puzzle_string = <<~TEXT
8 5 0 |0 0 2 |4 0 0
7 2 0 |0 0 0 |0 0 9
0 0 4 |0 0 0 |0 0 0
------+------+------
TEXT
result = SudokuPuzzle... | true |
dade17ba3be69f9ae9fbae1c8eea8162290195e7 | Ruby | jmils/RubytheHardWay | /ex39.rb | UTF-8 | 2,101 | 4.5625 | 5 | [] | no_license | #create a mapping of state to abbreviation.
#State is the key, abbreviation is the value
states = {
'Oregon' => 'OR',
'Florida' => 'FL',
'California' => 'CA',
'New York' => 'NY',
'Michigan' => 'MI'
}
#create a basic set of states and some cities in them
#City abbrev is the key, city name is the value
cities = {
'CA'... | true |
9e7ddbfc77d871ea639fe2e21e0cf487832a3992 | Ruby | podshara/rk | /lib/rk.rb | UTF-8 | 2,407 | 3.453125 | 3 | [
"MIT"
] | permissive | # Module for including +rk+ to global namespace (class Object).
module Rk
# Build Redis keys of several elements.
# rk("user", 10) => "user:10"
class Rk
attr_accessor :separator, :prefix, :suffix, :keys
# Set defaults
# * <tt>separator</tt> - :
# * <tt>prefix</tt> - empty
# * <tt>suffix</t... | true |
75fb22e86c722c13c88e3a2fbb661061ff1c232e | Ruby | albertbahia/wdi_june_2014 | /w02/d02/sean_jennings/cars/lib/deloream.rb | UTF-8 | 326 | 3.421875 | 3 | [] | no_license |
class Delorean < Car
def initialize(horsepower,fuel,current_time)
@horsepower = horsepower
if fuel > 5
@fuel = 5
elsif fuel < 0
@fuel = 0
else
@fuel = fuel
end
@current_time = current_time
end
def time_travel(year)
if year > 0
@current_time = year
end
end... | true |
e7fdf59b5199ceefddb1f1f4a93614fff7fcb749 | Ruby | CarlosUvaSilva/pikachu | /randomizer.rb | UTF-8 | 171 | 2.546875 | 3 | [] | no_license | class Randomizer
def initiliaze
@pokemons = ["media/bulbasaur.png","media/pikachu.png","media/raichu.png"]
end
def random_poke
pokemons.sample
end
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.