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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
abd1b1ae5b7590e5c9b8bf38ddd1204af3e3ea2e | Ruby | alubling/momeant | /app/models/thank_you_level.rb | UTF-8 | 1,180 | 2.515625 | 3 | [] | no_license | class ThankYouLevel < ActiveRecord::Base
belongs_to :user
has_many :achievements, class_name: "ThankYouAchievement"
has_many :achievers, through: :achievements, source: :user
validates :amount, numericality: true
validates :item, presence: true
default_scope order("amount ASC")
def self.check_for... | true |
ccd7ad14c93f447cb0a3a088d4fab7b35faeee69 | Ruby | weimingtom/Spaceshooter | /src/ResourceManager.rb | UTF-8 | 835 | 2.71875 | 3 | [] | no_license | class ResourceManager
def initialize(window)
@window = window
@resources = {}
end
def load_image(key, path)
raise IOError, 'path must point to a existing file!' unless File.file?(path)
@resources[key] = Gosu::Image.new(@window, path, false) if @resources[key].nil?
end
def load_font(key, path... | true |
86431512a1f73f81b7a17af5a40d4f25aacd7568 | Ruby | muuuuuuuuuu/Ruby.study | /perfect.ruby/yield.rb | UTF-8 | 335 | 3.5625 | 4 | [] | no_license | def block_sample
puts "stand up"
yield
puts "sit down"
end
block_sample do
puts "wolk"
end
stand up
wolk(yieldでwolkが呼び出された)
sit down
-----------------------------------------
def with_current_time
yield Time.now
end
with_current_time do |now|
puts now.year
end
2018
--------------------------------------
| true |
8299b20ac4a5ed517742dbab16bba6317ac85e90 | Ruby | zvickery/cubing-code | /utils/combos.rb | UTF-8 | 1,282 | 3.65625 | 4 | [] | no_license | #!/usr/bin/env ruby
# Add a factorial method for integers
class Integer
def fact
(1..self).reduce(:*) || 1
end
end
# Compute the number of permutations for the given dimension.
# Assumes NxNxN non-supercube.
class CubeCombinations
def initialize(dimension)
@dim = dimension
end
def combos
term1 ... | true |
b389b25f9e3f1f6fc66597aca2f6066e29787073 | Ruby | ArturT/team-scheduler | /app/models/default_day.rb | UTF-8 | 144 | 2.90625 | 3 | [] | no_license | class DefaultDay
attr_reader :date, :hours
def initialize(date, hours)
@date = date
@hours = hours
end
def id
-1
end
end | true |
9dbbb1e918a19edfeea7a7944991612974751fb1 | Ruby | leannkim11/array-CRUD-lab-v-000 | /lib/array_crud.rb | UTF-8 | 837 | 3.734375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
array = Array.new
end
def create_an_array
array=["one", "two", "three", "four"]
end
def add_element_to_end_of_array(array, element)
array = []
array << "element_one"
array.push("arrays!")
end
def add_element_to_start_of_array(array, element)
array = []
array.unshift("wow")
end... | true |
99629c998592974c1155c6c98666b397a20bf59f | Ruby | ivanionut/old-study | /ruby/expressions/redefining_backquotes_test.rb | UTF-8 | 324 | 2.671875 | 3 | [] | no_license | require 'test/unit'
alias old_backquote `
def `(cmd)
result = old_backquote(cmd)
if $? != 0
puts "Command: [#{cmd}] failed with status: [#{$?.exitstatus}]!"
end
result
end
class RedefiningBackquotesTest < Test::Unit::TestCase
def test_1
print `ls -l /etc/passwd`
print `ls -l /etc/wibble`
end
... | true |
50cd6c70910d5e60762a732a5d2b0565e9a3ed5c | Ruby | perpepajn25/oo-kickstarter-web-080717 | /lib/backer.rb | UTF-8 | 235 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class Backer
attr_accessor :backed_projects
attr_reader :name
def initialize(name)
@backed_projects = []
@name = name
end
def back_project(project)
@backed_projects << project
project.backers << self
end
end
| true |
07ab960859e6ea32b0ae0e3dbd65d8b673bea7a4 | Ruby | DoxingMethod/AntiCF | /anticf.rb | UTF-8 | 3,267 | 2.765625 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: UTF-8
require 'net/http'
require 'open-uri'
require 'json'
require 'socket'
require 'optparse'
def banner()
red = "\033[01;31m"
green = "\033[01;32m"
puts "\n"
puts" █████╗ ███╗ ██╗████████╗██╗ ██████╗███████╗"
puts"██╔══██╗████╗ ██║╚══██╔══╝██║██╔════╝██╔════╝"
puts"███████║██╔██╗... | true |
e37d9ec1f1051c2a1bc378a280d1210d210bbe14 | Ruby | daxadax/quotes | /lib/quotes/gateways/quotes_gateway.rb | UTF-8 | 2,089 | 2.59375 | 3 | [
"MIT"
] | permissive | module Quotes
module Gateways
class QuotesGateway < Gateway
def initialize(backend = nil)
@backend = backend || backend_for_quotes
@marshal = QuoteMarshal
end
def add(quote)
ensure_valid!(quote)
@backend.insert(serialized(quote))
end
def get(uid)
... | true |
e3630fd4e2f8972b8e74dcc9285b39d1f66ce05c | Ruby | jacegu/mog | /spec/mog/post_dir_spec.rb | UTF-8 | 3,431 | 2.5625 | 3 | [] | no_license | require 'spec_helper'
module Mog
describe PostDir do
let(:dir){ double :opened_directory }
let(:path){ '/path/to/the/directory' }
before do
dir.stub(:path).and_return(path)
end
it 'has a path' do
PostDir.new(dir).path.should == path
end
describe '::from directory' do
... | true |
30d9e6d57a3e5a5eac18a56c11065eb61a688e2a | Ruby | FrankGerold/ruby-enumerables-generalized-map-and-reduce-lab-nyc-web-102819 | /lib/my_code.rb | UTF-8 | 668 | 3.75 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # i might be overreacting but this ACTUALLY seems mind blowing
def map (array)
new_array =[]
array.length.times do
|entry|
new_array[entry] = yield(array[entry])
end
new_array
end
def reduce (array, start=nil) #copied this from the youtube video because my way was passing all tests except the 10th o... | true |
ccd7ba9a2002197b255149e13cb58857e8692abc | Ruby | GuilhermeMedeiross/URI | /Beginner/1181 - Line in Array.rb | UTF-8 | 351 | 3.015625 | 3 | [] | no_license | objective = gets.to_i
operation = gets.to_s.strip
matrix = Array.new(12) {Array.new(12)}
total = []
for i in 0..11
sum = 0
for j in 0..11
number = gets.to_f
matrix[i][j] = number
sum += number
end
total[i] = sum
end
if operation == 'M'
total[objective] = total[objective].qu... | true |
1e84e36bc614d0501ecee6353be19b4aab89ba51 | Ruby | kjjgibson/Morokufy | /lib/game_server/model/leaderboard.rb | UTF-8 | 571 | 2.796875 | 3 | [] | no_license | # A representation of the Game Server Leaderboard and all of it's attributes
module GameServer
module Model
class Leaderboard
attr_accessor :id, :name, :max_players, :point_type, :period, :period_value, :tags, :players
def initialize(id, name, max_players, point_type, period, period_value, tags, pl... | true |
8c35d5a0df04062ad6f1fe8ae9fc81f37a0eb402 | Ruby | Bayonnaise/Design-Patterns | /2-strategy-pattern/spec/report_spec.rb | UTF-8 | 1,291 | 2.875 | 3 | [] | no_license | require 'report'
describe Report do
it 'prints an html form' do
report = Report.new do |context|
puts '<html>'
puts ' <head>'
puts " <title>#{context.title}</title>"
puts ' </head>'
puts ' <body>'
context.text.each do |line|
puts " <p>#{line}</p>"
end
puts ' </body>'
puts '<... | true |
d91803d7fafe2317ada59aa8acfcae1aa4eefefd | Ruby | thinkerbot/configurable | /lib/configurable.rb | UTF-8 | 1,438 | 3.0625 | 3 | [
"MIT"
] | permissive | require 'configurable/module_methods'
# Configurable enables the specification of configurations within a class
# definition. Include and declare configs as below.
#
# class ConfigClass
# include Configurable
# config :one, 'one'
# config :two, 'two'
# config :three, 'three'
# end
#
# c = Confi... | true |
8b206b6a1cc00f4a9fe97a4ee1e5848a355836bb | Ruby | BaoPham92/simetro | /app.rb | UTF-8 | 581 | 2.5625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
require_relative 'metro'
@num_stops = []
if params[:start] - params[:end] == 0
@num_stops << params[:start].to_i = erb: trip_info
else
@num_stops << params[:end].to_i = erb: trip_info
get '/' do]
@num_stops
@lines = metro.keys
erb :index
end
get '/start' do
pa... | true |
8319124ae7d419b4d5be96bb61f500dcc392f121 | Ruby | roccia/baidu_scarpper | /sum.rb | UTF-8 | 401 | 3.234375 | 3 | [] | no_license | class Sum
def list
a = 0
until a > 10 do
p a
a += 1
end
a
end
# def test(n, m)
# #count = 0
# if some_method(n,m) != 5
# 5.times do
# puts some_method(n,m)
# if some_method(n,m) ==5
# break
# end
#
# puts "pause #... | true |
6cba74f2d6b64cd2e347e72634f0b7530e89d3cc | Ruby | flori/term-ansicolor | /lib/term/ansicolor.rb | UTF-8 | 3,967 | 2.859375 | 3 | [
"Apache-2.0"
] | permissive | require 'tins/xt/full'
module Term
# The ANSIColor module can be used for namespacing and mixed into your own
# classes.
module ANSIColor
require 'term/ansicolor/version'
require 'term/ansicolor/attribute'
require 'term/ansicolor/rgb_triple'
require 'term/ansicolor/hsl_triple'
require 'term/... | true |
7965564aae3360e04bbc6e51183854af9f7512bf | Ruby | jaycevdl/Learning-Ruby | /Table-of-Contents.rb | UTF-8 | 2,085 | 4.25 | 4 | [] | no_license | # Formatting and Creating a table of contents
p= "Page "
c1= "Chapter 1"
c2= "Chapter 2"
c3= "Chapter 3"
c4= "Chapter 4"
line_width= 25
puts""
puts""
puts""
puts"Hello, I am going to help you build a table of contents, We are going to start with the name of your book."
puts""
puts"What is the name of your book?"
title=... | true |
c1742079f43b1010cca36c693428c8abd7d2cf90 | Ruby | JonMaia/Replicables | /src/replicable.rb | UTF-8 | 1,546 | 2.765625 | 3 | [
"MIT"
] | permissive | require_relative '../src/MessageHistory'
require_relative '../src/Branch'
module MetodoCopiableYRegistable
def method_added(name)
return if @added
@added = true
original_method = "original_#{name}"
alias_method original_method, name
if name.to_s != "initialize"
define_method(name) do... | true |
543222402a102087d0fbbb7b04e69d5589a3959a | Ruby | plentz/lol_dba | /lib/lol_dba/sql_migrations/migration.rb | UTF-8 | 1,188 | 2.59375 | 3 | [
"MIT"
] | permissive | module LolDba
class Migration
attr_reader :full_name, :writer
def initialize(migration_file)
@full_name = File.basename(migration_file, '.rb')
@writer = LolDba::Writer.new("#{@full_name}.sql")
require Rails.root.join(migration_file)
end
def number
/^(\d+)_(.*)$/.match(full_na... | true |
df9471c29326216302e4dff9037c3c044b8ba035 | Ruby | Andr3mo/fullstackforum | /app/controllers/posts_controller.rb | UTF-8 | 1,286 | 2.6875 | 3 | [] | no_license | class PostsController < ApplicationController
# calls the method find_post before the show, edit, update and destroy methods
# DRY Principle
before_action :find_post, only: [:show, :edit, :update, :destroy]
# Uses a method from Devise to force the user to login before any action other than view index and show page... | true |
d6196016171addafde93bee0afb00c98872c47da | Ruby | BenRKarl/WDI_work | /w01/d04/Wake_Lankard/eleven.rb | UTF-8 | 380 | 3.703125 | 4 | [] | no_license | print "What's the volume of the amp? "
cur_vol = gets.chomp.to_i
print "Are we going over the cliff? "
crank = gets.chomp.downcase[0]
if ["y","n"].include?(crank)
if cur_vol < 11 && crank == "yes"
puts "Crank it to 11."
elsif cur_vol < 11 && crank == "no"
puts "You are lame."
else
puts "Crank in on... | true |
5cdf2f67f841dc5c9316549d9c48cb56e48a7d13 | Ruby | Sepheus/ProjectEuler | /Ruby/Euler357.rb | UTF-8 | 2,140 | 3.390625 | 3 | [] | no_license | require 'prime'
#primeTable = Hash.new(false)
#def primes(max)
# nums = Array.new(max + 1, 1)
# nums[0] = nums[1] = 0
#
# (2..Math.sqrt(max)).each do |sieve|
# if nums[sieve] == 1
# (2 * sieve).step(max, sieve).each do |num|
# nums[num] = 0
# end
# end
# end
# (2..max).select { |num| nums[... | true |
5eae24baa941e1d4bcb6c60533103a70f839a94b | Ruby | calebrauscher/The-Odin-Project | /Ruby/enumerable.rb | UTF-8 | 2,501 | 3.734375 | 4 | [] | no_license | module Enumerable
def my_each
for i in self do
yield(i)
end
self
end
def my_each_with_index
indx = 0
for i in self do
yield(i, indx)
indx += 1
end
self
end
def my_select
result = self.dup
self.my_each { |i|
unless yield(i)
... | true |
cb86d2570ed7a8f4f56f9e8e8be7f406fe12b77b | Ruby | brad-steveo/servizio-stage-testing | /Active Tests/Contract Creation.rb | UTF-8 | 2,045 | 2.65625 | 3 | [] | no_license | require "selenium-webdriver"
require "rspec"
require "require_all"
require_all "#Classes"
describe "Opens Contracts resource and creates a contract" do
it "Verifies that contract creation was successful" do
@driver = Selenium::WebDriver.for :chrome
#General Test Variables
timestamp = Time.now.strftime("%m/%d/... | true |
2211a0c60b0e9efc89c61d61157ca649e36ebce9 | Ruby | linkonsat/hangman | /objects/turn.rb | UTF-8 | 560 | 3.453125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'game'
require_relative 'display'
#handles the turn
class Turn
attr_accessor :word, :current_letters
def initialize(word, current_letters)
@word = word
@current_letters = current_letters
end
def player_display(word,current_letters,guess)
i = 0
whil... | true |
8703a3d4fe2b5bdf873eebbeb3952bb6dd6bf995 | Ruby | somebox/radio-ripper | /lib/podcaster.rb | UTF-8 | 4,513 | 2.5625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | require 'rss/0.9'
require 'rss/maker'
DEBUG=ENV['DEBUG']
class Podcaster
# Manages mp3 recordings:
# * traverses the mp3 download dir
# * examines each show directory for mp3s
# * sorts the mp3s by show date
# * combines multiple mp3s into one (due to disconnects)
# * copies the recording to the feed dire... | true |
c8aa1967ee73c1b0392530da551635f79c13cd07 | Ruby | scottmatsuda/badges-and-schedules-online-web-sp-000 | /conference_badges.rb | UTF-8 | 651 | 3.6875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(speakers)
badge_messages = []
speakers.each do |speaker|
badge_messages << "Hello, my name is #{speaker}."
end
return badge_messages
end
def assign_rooms(speakers)
room_assignments = []
speakers.each_with_index do ... | true |
1170d454a6bac13b418b8ae19c98c66290b8333f | Ruby | pawan9489/TeachingRuby | /DemoCode/Session5/1.LambdasAndFunctionalConcepts/1.WhyLambdas.rb | UTF-8 | 1,298 | 4.25 | 4 | [
"Unlicense"
] | permissive | =begin
Same as Procs but 2 differences:
1. Default values of proc parameters is nil.
2. Return keyword in a Proc will terminate the Outer function.
=end
squares_lambda = lambda {|n| n * n }
squares_proc = Proc.new {|n| n * n }
puts "---PROC----"
p [1,2,3].map(&squares_proc)
p squares_proc.call(5)
... | true |
f44cfdfd2d7c197cd992c4d0eb484238745c591e | Ruby | osak/Contest | /GCJ/2011/1A/A.rb | UTF-8 | 390 | 3.375 | 3 | [] | no_license | #!/usr/bin/ruby
require 'prime'
1.upto(gets.to_i) do |case_num|
n,pd,pg = gets.chomp.split.map(&:to_i)
possible = true
possible = false if (pg == 100 && pd != 100) || (pg == 0 && pd != 0)
a = 100 / 100.gcd(pd)
b = 100 / 100.gcd(100-pd)
possible = false if a > n || b > n || a*b/a.gcd(b) > n
... | true |
ffb27ad4bab6218d4b4cc00329d4ad80bf7e7ca4 | Ruby | washellington/bagzzBanking | /app/models/transaction.rb | UTF-8 | 438 | 2.609375 | 3 | [] | no_license | class Transaction < ApplicationRecord
belongs_to :account
belongs_to :transaction_category
attr_accessor :start_date, :end_date
validates :amount, :date_applied, presence: true
validates :amount, numericality: {greater_than: 0}
def net_amount
transaction_category.id == TransactionCategory::DEPOSIT ... | true |
d5c91c124f6de7ae3bcdb565339985480413647d | Ruby | AxialExchange/ruby-hl7 | /test/test_basic_parsing.rb | UTF-8 | 8,655 | 2.734375 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
require File.dirname(__FILE__) + '/test_helper'
class BasicParsing < Test::Unit::TestCase
def setup
@simple_msh_txt = TestHelper.load_hl7(:test).first
@empty_txt = TestHelper.load_hl7(:empty).first
@empty_segments_txt = TestHelper.load_hl7(:empty_segments).first
@base_msh = "MSH|^~\... | true |
bcc6e16ad9b41801aacb0cb3d89a171ab651cc7f | Ruby | zacisaacson/module_0_capstone | /day_1/ex6.rb | UTF-8 | 1,081 | 4.5 | 4 | [] | no_license | # assigning types_of_people to the value of 10
types_of_people = 10
# assigning x to a string within a string
x = "There are #{types_of_people} types of people."
# assigning binary to a value of "binary"
binary = "binary"
# assigning do_not to a vlaue of "dont"
do_not = "don't"
# assigning y to two strings within a str... | true |
7d6a43c1db3ac75a0912304ee6c6db95a314da2c | Ruby | jturello/contact_sinatra | /lib/contact.rb | UTF-8 | 666 | 2.609375 | 3 | [] | no_license | class Contact
attr_reader :first_name, :last_name, :job_title, :company, :id, :email
@@contacts = []
define_method(:initialize) do |attributes|
@first_name = attributes[:first_name]
@last_name = attributes[:last_name]
@job_title = attributes[:job_title]
@company = attributes[:company]
@id = @... | true |
9774b7d7039330797850498fe93005704b1c875c | Ruby | matelau/CentsRails | /scrapers/growth_scraper.rb | UTF-8 | 633 | 2.8125 | 3 | [] | no_license | require 'csv'
ENV['RAILS_ENV'] = "development" # Set to your desired Rails environment name
require_relative '../config/environment.rb'
class GrowthScraper
def self.scrape()
taxes = {}
arr = CSV::parse(File.open("../data/scraped/growth_trend.csv", 'r') {|f| f.read})
states = CSV::parse(File.open("../query_se... | true |
b88555339d507bf3edd076b4787df218e6627e41 | Ruby | speedyray/RubyPrograms | /Callable/extinclud_sing.rb | UTF-8 | 302 | 3.515625 | 4 | [] | no_license | module M
def self.included(c)
puts "#{self} included by #{c}"
end
def self.extended(obj)
puts "#{self} extended by #{obj}"
end
end
obj = Object.new
puts "Including M in object's singleton class:"
class << obj
include M
end
puts
obj = Object.new
puts "Extending object with M:"
obj.extend(M) | true |
ef1177b14c9ab3147f1ebac9158e665204a6bebc | Ruby | bingyujin/ruby_test | /features/gherkin_sample.rb | UTF-8 | 1,663 | 2.921875 | 3 | [] | no_license | require 'minitest'
Given('a global administrator named {string}') do |string|
# puts 'background given: ' + string
end
Given('a blog named {string}') do |string|
# puts 'background given: ' + string
end
Given('a customer named {string}') do |string|
# puts 'background given: ' + string
end
Given('the following pe... | true |
3f515d5cefb1bd89eb1a6f2c8b558a18dbc69270 | Ruby | ssoonmi/aA-Projects | /W2D3-master/poker/spec/hand_spec.rb | UTF-8 | 3,315 | 3.421875 | 3 | [] | no_license | require 'hand'
describe Hand do
subject(:hand) {Hand.new}
# pairs, 3-of-a-kind, 4-of-a-king, straight, flush
let(:card1){double('Card', value: 10, suit: :hearts)}
let(:card2){double('Card', value: 10, suit: :spades)}
let(:card3){double('Card', value: 11, suit: :hearts)}
let(:card4){double('Card', value: 11... | true |
c4a1c917c5733b90894613006486ee8fb968a615 | Ruby | CartoDB/cartodb | /app/controllers/carto/api/overlay_presenter.rb | UTF-8 | 652 | 2.5625 | 3 | [
"LicenseRef-scancode-generic-cla",
"BSD-3-Clause"
] | permissive | module Carto
module Api
class OverlayPresenter
PUBLIC_VALUES = [:id, :order, :type, :template, :options, :visualization_id].freeze
VIZJSON_VALUES = [:type, :order, :options, :template].freeze
def initialize(overlay)
@overlay = overlay
end
def to_poro
values(@overl... | true |
0a974979901144a0baba13611a92648fb01e37ab | Ruby | mwagner19446/wdi_work | /w07/d04/Kevin/weather.rb | UTF-8 | 523 | 3.125 | 3 | [] | no_license | require 'httparty'
city = ARGV[0]
state = ARGV[1]
the_weather = HTTParty.get("http://api.wunderground.com/api/fe15bba3dcbb52e5/conditions/q/#{state}/#{city}.json")
the_temp = the_weather["current_observation"]["temp_f"]
puts "THE CURRENT TEMPERATURE IS: #{the_temp} DEGREES F"
hourly_weather = HTTParty.get("http://... | true |
6096f16d8a6660b8f732ed66f3c168e6f2ae4c98 | Ruby | nydame/address-bloc | /models/address_book.rb | UTF-8 | 1,791 | 3.609375 | 4 | [] | no_license | require_relative 'entry'
# in addition, import the CSV class
require "csv"
# AddressBook model
class AddressBook
attr_reader :entries
def initialize
@entries = []
end
def add_entry(name, phone_number, email)
index = 0
@entries.each do |entry|
if name < entry.name
... | true |
83a10a14e59a0724c8bef990a7295df47a742bef | Ruby | rubyworks/stick | /work/consider/algebra-0.72/lib/algebra/numeric-supplement.rb | UTF-8 | 1,396 | 3.03125 | 3 | [
"MIT"
] | permissive | # Numeric Supplements
#
# by Shin-ichiro Hara
#
# Version 1.01 (2001.04.10)
class Numeric
def self.unity; 1; end
def self.zero; 0; end
def zero; self.class.zero; end
def unity; self.class.unity; end
def self.indeterminate(x)
eval(x)
end
def self.const(x); x; end
def each; end
def pdivmod(other)... | true |
04e1363fa42cd8e62af05facb28d1f31f85fa774 | Ruby | jonzingale/RubyProcessing | /ode/complex_ode_vector.rb | UTF-8 | 1,000 | 2.890625 | 3 | [] | no_license | require 'matrix'
require 'cmath'
include CMath
def setup
size(displayWidth, displayHeight)
colorMode(HSB,360,100,100,100)
@w, @h = [width/2, height/2]
frame_rate 10
background(0)
stroke(210,100,100,100)
stroke_width 1
@pts = points 9000
@del_t = 0.03
end
def cent_rand ; 10 * (rand - 1 * rand) ... | true |
c2b80d76f26822b01c7f972577e4320b21a619ec | Ruby | ShujaatAzim/module-one-final-project-guidelines-dc-web-051319 | /app/models/city_hash_train.rb | UTF-8 | 1,112 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #returns the hash of cities to travel to by train
def city_hash_trains
cities = {
"Tokyo, Japan" => 300,
"Sapporo, Japan" => 700,
"Seattle Washington, United States" => 180,
"New York City, United States" => 370,
"Istanbul, Turkey" => 526,
"Düsseldorf, Germany" => 217... | true |
617b7db6b11ca4c189f5b84ca7a425b466683d71 | Ruby | simonwex/Ruby-for-Ski-Bums-Exercises | /lessons/01_working_with_arrays/03_adding_to_an_array.rb | UTF-8 | 551 | 3.484375 | 3 | [] | no_license | #!/usr/bin/ruby
# Consider this part magic for now. We'll get to it in a later lesson
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
# Here we have an array of symbols
an_array = [:a, :b, :c]
# append to that array, and add the symbols :d and :e
# Here is the documentation for Array:... | true |
2d07762dfcdc08225e0a988bd90fe9d57f48ef5a | Ruby | hasumin71/rensyu | /paiza.rb | UTF-8 | 11,144 | 4.09375 | 4 | [] | no_license | #文字の重複カウント
query = gets.chomp
source = gets.chomp
puts source.count(query)
#文字列の n 文字目と n + 1 文字目
n = gets.chomp.to_i
s = gets.chomp
puts s[n-1]+" "+s[n] if s[n]
#文字列の重複カウント
pattern = gets.chomp #次に取得する文字列の重複部分を取得
string = gets.chomp #テストされる文字列を取得
result = 0 #結果の初期値設定
(0..(string.size - pattern.size)).each do |i... | true |
47adbba922d51444e3f1c46cf7a04925d83c2791 | Ruby | trishume/DWITE-solutions | /DWITE 2011 round 1/q1.rb | UTF-8 | 418 | 2.765625 | 3 | [] | no_license | debug = false
input = debug ? STDIN : File.new("DATA1.txt","r")
out = debug ? STDOUT : File.open("OUT1.txt", 'w')
#tsetnoc siht ni snoitseuq 567 era ereht
5.times do
line = input.gets
reversed = line.reverse
toks = reversed.split(" ")
results = []
toks.each do |t|
res = t
if (t =~ /^[0-9]+$/)... | true |
eb69462c5db2c1fdee763fa73c1978a999f5b16c | Ruby | sethbass14/sinatra-mvc-lab-web-103017 | /models/piglatinizer.rb | UTF-8 | 715 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
attr_reader :text
def initialize
end
def piglatinize(word)
vowels = %w(a e i o u)
if vowels.include?(word[0].upcase) || vowels.include?(word[0].downcase)
word + "way"
elsif word[0] == 'q' && word[1] == 'u'
pig = word.slice(2..-1) + "quay"
else
vowel_index... | true |
a2e01aec03dc260d2b3a905507a4c03638df4f77 | Ruby | serkaniyigun/ruby-playground | /getipaddress.rb | UTF-8 | 520 | 2.625 | 3 | [] | no_license | require 'JSON'
require 'open-uri'
require 'net/smtp'
def send_email
ex_ip = open( 'http://jsonip.com/ ' ){ |s| JSON::parse( s.string())['ip'] }
puts ex_ip
message = <<MESSAGE_END
From: serkan
To: master
subject: TEST from ruby
Date: #{Time.now.rfc2822}
my ip address #{ex_ip}
MESSAGE_END
smtp = Net::SMTP.new 'sm... | true |
1fcac88661be9f1ca29fbde3dcdccfa07b259227 | Ruby | adambure21/ruby_code_snippets | /Dec5/box_class.rb | UTF-8 | 2,022 | 3.765625 | 4 | [] | no_license | #Contents are modified
#To access the classname of the current onject we can use the method of the class is
#Object_name.class = Will give name of Class.
#Object_name.main = Will give
#Object_name.inspect
#self.inspect = Can be used as Debugging tools.& will give internal details about object.
#class_name.superclas... | true |
12597aba3ebf54cfcc219ef9f1a0274c9881db04 | Ruby | FranzVC/JuegoAuto | /lib/Auto.rb | UTF-8 | 1,989 | 3.734375 | 4 | [] | no_license | class Auto
def initialize()
@posX=1
@posY=1
@orientacion='S'
@nombre="salmonela"
end
def getPosX()
return @posX
end
def getPosY()
return @posY
end
def getNombre()
return @nombre
end
def getNombre()
@nombre
end
... | true |
bedbe1da85c264daf9b996a8c69512e84487bfdb | Ruby | shaurya157/LRUCache | /lib/p02_hashing.rb | UTF-8 | 339 | 3.15625 | 3 | [] | no_license | class Fixnum
# Fixnum#hash already implemented for you
end
class Array
def hash
self.each_with_index.inject(0) do |temp_hash, (val, idx)|
(val.hash + idx.hash) ^ temp_hash
end
end
end
class String
def hash
self.chars.map(&:ord).hash
end
end
class Hash
def hash
self.to_a.sort_by(&:ha... | true |
63407813fe4fa149131e401789163a280e3bb781 | Ruby | brandonlilly/adventofcode-challenges | /day6/day6.rb | UTF-8 | 1,215 | 3.1875 | 3 | [] | no_license | lines = File.readlines('input.txt').map(&:chomp)
def render(grid)
grid.transpose.map do |col|
col.map do |cell|
cell ? 1 : 0
end.join(' ')
end.join("\n")
end
def display(grid)
puts render(grid)
end
def set_cells(grid, corner1, corner2, &prc)
left, right = [corner1.first, corner2.first].sort
t... | true |
500eabe46914d163b5c9d95944889fbbd523f197 | Ruby | seven1m/adventofcode | /2018/day04.rb | UTF-8 | 645 | 2.703125 | 3 | [] | no_license | events=ARGF.read.split(/\n/).sort
guards={}
guard=nil
asleep=nil
events.each do |event|
case event
when /Guard #(\d+)/ then guard=$1.to_i
when /(\d\d)\].*asleep/ then asleep=$1.to_i
when /(\d\d)\].*wakes/
guards[guard] ||= []
(asleep...$1.to_i).each { |m| guards[guard][m] = guards[guard][m].to_i + 1 }
... | true |
9794ca4374548d8bba06f7266a3b4898d5bcb4e7 | Ruby | gcrk/seir41-homework | /Yang Wu/week4/Tuesday/MTA.rb | UTF-8 | 3,683 | 4.28125 | 4 | [] | no_license | # # MTA Lab
#
# ## Objectives:
# * Apply your knowledge of Ruby to solve a real world problem.
# * Get really good at array manipulation.
#
# #### Activity
# * Create a program that models a simple subway system.
#
# * The program takes the line and stop that a user is getting on at and the line
# and stop that user is... | true |
7b7a84d1a1f5a09811e0015705040edca1626e22 | Ruby | fog/fog-core | /lib/fog/core/time.rb | UTF-8 | 587 | 2.84375 | 3 | [
"MIT"
] | permissive | require "time"
module Fog
class Time < ::Time
DAYS = %w(Sun Mon Tue Wed Thu Fri Sat).freeze
MONTHS = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec).freeze
def self.now
at(::Time.now - offset)
end
def self.now=(new_now)
old_now = ::Time.now
@offset = old_now - new_now
... | true |
98f8ce6a00c918c5072e11073691f92626769bc8 | Ruby | jshorns/oyster-cards | /spec/journey_spec.rb | UTF-8 | 2,263 | 2.90625 | 3 | [] | no_license | require 'journey'
describe Journey do
let (:max_fare) { Journey::PENALTY_FARE }
let (:min_fare) { Journey::MIN_FARE }
let (:station) { double(:station, :name => "Brixton", :zone => "Zone 2") }
let (:station2) { double(:station, :name => "Seven Sisters", :zone => "Zone 3") }
it { is_expected.to respond_to :e... | true |
35e4cc59bcce685aa0397df6a7d43a1262cee3e3 | Ruby | MoizHasan/Test-First-Ruby | /01_temperature/temperature.rb | UTF-8 | 122 | 3.109375 | 3 | [] | no_license | def ftoc(temp)
return (temp-32) * 5/9
end
def ctof(temp)
temp = temp + 0.00
temp = (temp * 9/5) + 32
return temp
end
| true |
f7b4db7d81aab98a82bcd02048b30348e6b29ff3 | Ruby | Gratisin-Coding/danasura | /api/controllers/user_controller.rb | UTF-8 | 426 | 2.65625 | 3 | [] | no_license | require_relative '../models/user'
class UserController
def login(params)
user = User.new(params)
if (user.login == 200)
return "Success"
else
return "Failed"
end
end
def register(params)
user = User.new(params)
if (user.regi... | true |
2a0f2aab7c3ea1a06cc53c7356b322eeb088fca0 | Ruby | natanael-araujo/ht-rmp | /spec/files/day_1_spec.rb | UTF-8 | 2,040 | 2.984375 | 3 | [] | no_license | require "spec_helper"
describe "Exercises: Day 1" do
context "Exercise #1" do
it "should define Object#metaclass" do
Object.should respond_to(:metaclass)
end
it "should not call singleton_class method" do
klass = Class.new
klass.expects(:singleton_class).never
klass.metaclass
... | true |
db01327aeb699172992860e31220af3ab2ddc1ee | Ruby | richardking/parser | /spec/accounts_spec.rb | UTF-8 | 674 | 2.625 | 3 | [] | no_license | require 'helper'
describe Accounts do
let(:accounts) do
accounts = Accounts.new
@acct1 = Account.new(1, 2)
@acct2 = Account.new(1, 3)
@acct3 = Account.new(2, 4)
accounts << @acct1
accounts << @acct2
accounts << @acct3
accounts
end
it 'should return the number of accounts' do
... | true |
d11f6f85769565377b4a1e325361fb90a1588dc0 | Ruby | mafeichao/minhash | /lib/minhash.rb | UTF-8 | 598 | 2.90625 | 3 | [
"MIT"
] | permissive | require 'murmur_hash'
module MinHash
VERSION = '0.9.9'
# We use murmur_hash64 because we really do need 2**64 -1 items and
# I'm assuming all the machines it will be deployed on are
# little-endian.
Infinity = 1.0 / 0.0
def self.minhash(history, seed)
val = Infinity
Array(history).each do |item|
... | true |
3834b83cdfe635bdda3760af8f27ac6544b79d0c | Ruby | sirisak-amivoice/aohs_old | /lib/utils/opt_parser.rb | UTF-8 | 1,390 | 2.90625 | 3 | [] | no_license | require 'hashie'
module AppUtils
#
# helper class for options or parameters
#
# main class
#
class OptParser
def self.parse(options={})
return new(options)
end
def initialize(opts)
@options = Hashie::Mash.new(mapopts(opts.to_h))
end
def options
retur... | true |
b1274e3242b5747c0afc0a3e2ecf9c602764d26a | Ruby | MG1222/ruby- | /pyramide.rb | UTF-8 | 319 | 3.359375 | 3 | [] | no_license | store = 0
while (store == 0) || (store > 25)
puts "Salut, bienvenue dans ma super pyramide ! Combien d'étages veux-tu (entre 1 - 25)?"
print "> "
store = gets.chomp.to_i
end
step = 1
store.times do
store.times do
print " "
end
step.times do
print "#"
end
step = step + 1
store = store - 1
puts
end | true |
47087f3327304fb28490dac93deb36417648f277 | Ruby | zilla7733/Katas | /StringCalulator 2/Calculator.rb | UTF-8 | 1,789 | 3.40625 | 3 | [] | no_license | class Calculator
def Add numbersToAdd
total = 0.0
numbersToAdd = GetCommaDelimitedNumbersToAdd(numbersToAdd)
VerifyThereAreNoNegativeNumbers(numbersToAdd)
numbersToAdd.split(",").each { |n|
if Float(n) <= 1000
total = total + Float(n)
end
}
return total
end
def GetCom... | true |
ad906c16c7faef649c0fa13e3e6d79748ef94ec4 | Ruby | javiguajardo/interview-prep | /design_patterns/iterator/change_resistant_internal_iterator.rb | UTF-8 | 143 | 3.015625 | 3 | [] | no_license | def change_resistant_for_each_element(array)
copy = Array.new(array)
i = 0
while i < copy.length
yield(copy[i])
i += 1
end
end
| true |
de60a5b9b7a0434c043640fded561ae8312ce8ac | Ruby | LApptelier/message_quickly | /lib/message_quickly/messaging/element.rb | UTF-8 | 1,088 | 2.640625 | 3 | [
"MIT"
] | permissive | module MessageQuickly
module Messaging
class Element < MessageQuickly::Messaging::Base
attr_accessor :title, :image_url, :subtitle, :buttons
def initialize(params = {})
self.buttons ||= []
super(params)
end
def build_button(button_type)
case button_type
... | true |
485bc97da0f864f310390cfe5261feae7f14a1d2 | Ruby | Jwatts82/NPS-PARKS-CLI-Project | /lib/api.rb | UTF-8 | 1,130 | 2.640625 | 3 | [
"MIT"
] | permissive | class API
def self.get_parks(state_code)
key=ENV["API_KEY"].split('=')[1]
url="https://developer.nps.gov/api/v1/parks?stateCode=#{state_code}&api_key=#{key}"
uri=URI(url)
response=Net::HTTP.get(uri)
parks=JSON.parse(response)["data"].each do |p|
Park.new(full_na... | true |
46e7115552de131f5cc03f643fcd1fe9a9fe3005 | Ruby | jhunschejones/Counseling-Book-Tags | /app/models/book.rb | UTF-8 | 3,868 | 2.671875 | 3 | [] | no_license | class Book < ApplicationRecord
has_many :tags, dependent: :destroy
has_many :comments, dependent: :destroy
has_and_belongs_to_many :authors
validates :title, :source, :source_id, :cover_url, presence: true
before_create :set_title_keywords
OPENLIBRARY = "openlibrary".freeze
GOODREADS = "goodreads".freeze
... | true |
00a33d32d2a4030baead7ed54c78d48bbf025af6 | Ruby | karkisandesh/upcoming_movies | /lib/upcoming_movies/movie_data.rb | UTF-8 | 483 | 2.6875 | 3 | [
"MIT"
] | permissive | # class UpcomingMovies::Movie_data
#
# attr_accessor :title, :release_date, :synopsis
# @@all = []
#
# def self.all
# @@all
# end
#
# def save
# @@all << self
# end
#
# def initialize(title, release_date, synopsis)
# @title = title
# @release_date = release_date
# @synopsis = synopsis
... | true |
c6bd1303fac221517a133ab70dedcc79ad70259a | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/0fc410ab0a4549e9855f4e98eead52e1.rb | UTF-8 | 233 | 3.3125 | 3 | [] | no_license | class Hamming
def self.compute(dna_first, dna_second)
count = 0
dna_first.chars.each_with_index do |symbol, index|
count += 1 if (symbol != dna_second[index]) && (dna_second[index] != nil)
end
count
end
end
| true |
8f220fe1a796f1abdeaf22d8daecc49bd4a4b39a | Ruby | monaant/Ruby | /01_types_variables/01 into Types Variables full name.rb | UTF-8 | 109 | 3.578125 | 4 | [] | no_license | puts "Your favorite number:"
number = gets.chomp.to_i
puts "Maybe it's your favorite number: #{number+1}"
| true |
f83203140f7b0021696cd5d86b44031fee9cfacf | Ruby | cwooley/object-relations-assessment-web-060517 | /solution.rb | UTF-8 | 2,002 | 3.328125 | 3 | [] | no_license | # Please copy/paste all three classes into this file to submit your solution!
#############################RESTAURANT###############################
class Restaurant
attr_accessor :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def self.find_by_nam... | true |
2e5a84099d5625d62c7f8573cbc8d1cef7991d32 | Ruby | AdamMusa/testa | /examples/ruby/my_ruby_app/divisionby2.rb | UTF-8 | 165 | 2.859375 | 3 | [
"MIT"
] | permissive | # ::testa_start::
# ::case_start::
# >> divisionby2(14)
# << 7.0
# ::case_end::
# ::code_start::
def divisionby2(a)
return a/2
end
# ::code_end::
# ::testa_end:: | true |
1717b3f53d9b1aa08a1b15f75960545088fcfc30 | Ruby | waterlink/cars_api | /lib/cars_util/equality.rb | UTF-8 | 506 | 3.03125 | 3 | [
"MIT"
] | permissive | require "cars_util"
module CarsUtil
# Equality knows when two objects are equal
module Equality
def def_equals(fields, file = __FILE__, line = __LINE__)
class_eval <<-ruby_eval, file, line + 1
def ==(other)
return false unless other.is_a?(self.class)
#{Equality.conditions_for(... | true |
564f14854fecdec3c29a28d083f174e07a1dfe0b | Ruby | wonda-tea-coffee/atcoder | /abc/049/a.rb | UTF-8 | 70 | 2.90625 | 3 | [] | no_license | puts [?a, ?i, ?u, ?e, ?o].include?(gets.chomp) ? 'vowel' : 'consonant' | true |
22d5f3af2ed56ff2cb06bbbb30bf26ec16028fcc | Ruby | bespokoid/doodle | /lib/doodle/inherit.rb | UTF-8 | 1,251 | 2.859375 | 3 | [
"MIT"
] | permissive | class Doodle
# = inherit
# the intent of inherit is to provide a way to create directives
# that affect all members of a class 'family' without having to
# modify Module, Class or Object - in some ways, it's similar to Ara
# Howard's mixable[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/197296]
... | true |
b4265f8cbce34f5cd2df239e257f5c99fe284bec | Ruby | emosowski/phase-0 | /week-4/variables-methods.rb | UTF-8 | 1,243 | 4.21875 | 4 | [
"MIT"
] | permissive | puts "Hello, what is your name"
name = gets.chomp
puts "What is your middle name?"
middle_name = gets.chomp
puts "What is your last name?"
last_name = gets.chomp
puts "Your name is " + name + " " + middle_name + " " + last_name + "!"
puts "What is your favorite number?"
number = gets.chomp
number = (number.to_i) + 1
p... | true |
196ca41973d63e899eef46c398e681b166a9d9b7 | Ruby | musiccity365/ruby-enumerables-introduction-to-map-and-reduce-lab-dc-web-030920 | /lib/my_code.rb | UTF-8 | 1,218 | 3.46875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'pry'
def map_to_negativize(source_array)
new = []
i=0
while i < source_array.length do
new.push( source_array[i] * -1)
i += 1
end
return new
end
def map_to_no_change(source_array)
new = []
i=0
while i < source_array.length do
new.push( source_array[i])
i += 1
end
return new
end
def map_to_no_... | true |
5f448134b3dafb10549217dca62e68da78ffeab7 | Ruby | ramlang/intro-to-programming-with-ruby | /intro_variables/var_ex_1.rb | UTF-8 | 206 | 4.03125 | 4 | [] | no_license | # Write a program called name.rb and ask user for name and puts greeting.
# my_answer =>
# name.rb
puts "Please enter your name: "
name = gets.chomp
puts "Greetings #{name}! I hope you have a great day!"
| true |
3abba09c376d58142a0eca739520761d5b36126c | Ruby | marcwright/WDI_ATL_1_Instructors | /REPO - DC - Students/w01/d02/Mary/searching_for_obi_wan.rb | UTF-8 | 910 | 3.375 | 3 | [] | no_license | puts "Hi, I'm C-3P0, human-cyborg relations."
puts "What is your name?"
name = gets.chomp
puts "It is a pleasure to meet you, #{name}. Have you ever met a protocol droid before?"
meet = gets.chomp
puts "#{meet}? How interesting, for someone from around these parts."
puts "I'm terribly sorry for prying, but you don't ... | true |
acfdfcffb150af9ac8cdcef460a0ecbae0cb4e7d | Ruby | jarthod/codejam | /2013/round-2/2-many-prizes/many-prizes.rb | UTF-8 | 881 | 3.328125 | 3 | [] | no_license | #!/usr/bin/env ruby
def min_range min, max, step, offset
return min if offset <= 0
width = (max-min)/step+1
return Float::INFINITY if offset >= width
#puts "min_range(#{min}, #{max}, #{step}, #{offset}) #{width}"
left = min_range(min, max-step, step*2, offset)
right = min_range(min+step, max, step*2, offs... | true |
56086eb2a82bebaf659b965ffc1c571820c2513b | Ruby | adrianomitre/Preisach | /triangle.rb | UTF-8 | 780 | 3.46875 | 3 | [] | no_license | require File.expand_path('../point', __FILE__)
class Triangle
def initialize(p0, p1, p2)
@vertices = [p0, p1, p2].sort
end
def area
unless @area
result = 0
@vertices.each_cons(2) do |a, b|
result += a.x*b.y - b.x*a.y
end
@area = result / 2.0
end
@area
end
... | true |
9a5348fca975aeea9f742fc23ff0e4b2a3f34266 | Ruby | Ciccillo73/homework_karaoke_bar | /specs/room_specs.rb | UTF-8 | 625 | 2.578125 | 3 | [] | no_license | require("minitest/autorun")
require('minitest/reporters')
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
require_relative("../room")
require_relative("../song")
require_relative("../guest")
require('pry-byebug')
class RoomTest < MiniTest::Test
def setup ()
@room = Room.new("Red", 5, 10)
end
... | true |
8152be8a5e9fdedf0ded2dd8e343dbf29b1b8fd2 | Ruby | coreycosman/method-assignment | /method-assignment-6.rb | UTF-8 | 163 | 3.21875 | 3 | [] | no_license | def converter(any_number)
puts any_number -32 * 1.8
end
puts "enter a farenheit value for conversion"
user_input = gets.chomp.to_i
puts converter(user_input)
| true |
2a84f8e86f792bceae0bb091811791dbc127e834 | Ruby | 0xDing/acs2aws | /lib/acs2aws/cli/config.rb | UTF-8 | 792 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'clamp'
require 'colorize'
require 'uri'
module Acs2aws
module Cli
class ConfigCommand < Clamp::Command
option %w(-v --version), :flag, 'print version information' do
puts "acs2aws: version #{Acs2aws::VERSION}\n\n"
exit(0)
end
def execute
... | true |
e340a7037ec60ab79eadaaa90707ad5d6679bec2 | Ruby | hopetds/ruby | /day-3/5_methodd.rb | UTF-8 | 356 | 3.75 | 4 | [] | no_license | #!/usr/bin/env ruby
class Array
def odd_methodd
(self.select! {|i| yield(i)}).reject! { |i| not i%2 == 0}
end
end
puts [1, 2, 3, 4, 5, 6, 7].odd_methodd { |i| i > 2}.inspect # => [4, 6]
puts [1, 2, 3, 4, 5, 6, 7].odd_methodd { |i| i > 10}.inspect # => nil
puts [2, 4, 6, 8, 10, 12, 7].odd_methodd {|i| i.between?(... | true |
70a751f2a77ab97b6d61949e070735ae6e13378b | Ruby | Pignataro67/sinatra-mvc-lab-v-000 | /models/piglatinizer.rb | UTF-8 | 429 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
attr_reader :text
def piglatinize(text)
if text.start_with?('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')
text = text + "way"
else
num = text.index(/[aeiou]/)
t_string = text.slice!(0..num - 1)
text = text + t_string + "ay"
end
text
end
def to_pi... | true |
98b16d1b42a6c6869b1dfbbdd49bedd6fa8881a1 | Ruby | khoifishpond/backend_mod_1_prework | /section4/exercises/person.rb | UTF-8 | 491 | 4.6875 | 5 | [] | no_license | # Create a person class with at least 2 attributes and 2 behaviors.
# Call all person methods below the class and print results
# to the terminal that show the methods in action.
class Person
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
def eat(food)
p "#{name} ea... | true |
13aaf8dae034dca003b93a335e9164514d396a99 | Ruby | judearasu/projecteuler | /ruby/p3_prime.rb | UTF-8 | 361 | 3.953125 | 4 | [] | no_license | #The prime factors of 13195 are 5, 7, 13 and 29.
#What is the largest prime factor of the number 600851475143 ?
def prime(number)
factors=[]
divider=2
while number > 1
while number%divider==0
factors.push(number)
number/=divider
end
divider+=1
end
return factors
end
prime_factors=prime(600851475143)
pr... | true |
028ca4e0e784d8330f28bd00da7f42c972c86a64 | Ruby | frubilarz/2TLPP | /node.rb | UTF-8 | 1,235 | 3.359375 | 3 | [] | no_license | class Node
def initialize(node,mesh)
lista = []
File.open(node+'.node','r') do |f| #en espiral.lista estan las coordenadas de los puntos
while linea = f.gets
lista << linea.delete("\n") #chop elimina el ultimo caracter en este caso el salto de linea
end
end
for i in 0..lista.len... | true |
b5e9ca74909c03174747147a723cef664568c99b | Ruby | jmks/string_kata_plugin | /lib/string_kata_plugin/string_calculator.rb | UTF-8 | 1,364 | 3.3125 | 3 | [
"MIT"
] | permissive | module StringKataPlugin
module StringCalculator
extend self
DELIMITER_PREFIX = "//"
def add(calculation)
return 0 if calculation.empty?
delimiter, delimited_numbers = extract_delimiter(calculation)
numbers = extract_numbers(delimited_numbers, delimiter)
validate_numbers!(numbe... | true |
a54e52411daeb8d8585bf86c297e2dcfad082f1b | Ruby | nurrutia/pruebaruby2 | /ejercicio4.rb | UTF-8 | 198 | 3.734375 | 4 | [] | no_license | class Complejo
attr_accessor :x , :y
def initialize(x, y)
@x = x
@y = y
end
def doble(complejo)
Complejo.new(@x + complejo.x, @y + complejo.y)
end
end
a = Complejo.new(1,2)
puts a.doble(a) | true |
2f7a82119d653685cac7d5fec52b379ceecd696e | Ruby | aquariumbio/microtiter-plates | /libraries/PlateLayoutGenerator.rb | UTF-8 | 3,200 | 3.03125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# Factory class for instantiating `PlateLayoutGenerator`
#
# @author Devin Strickland <strcklnd@uw.edu>
class PlateLayoutGeneratorFactory
# Instantiates `PlateLayoutGenerator`
#
# @param group_size [FixNum] the size of groups of wells, e.g., corresponding
# to replicates
# @re... | true |
d02b095947130518cf82dad3fccf41bcc6d82113 | Ruby | tibbsa/launchschool | /RB101-109-Exercises/easy_1/how_many_test.rb | UTF-8 | 1,019 | 4.15625 | 4 | [] | no_license | # RB101-109 Small Problems
# Easy 1, Question 4 - How many?
# https://launchschool.com/exercises/d5c51b39
#
# Write a method that counts the number of occurrences of each
# element in a given array.
#
# Test: With large arrays, what is faster?
# Disabled "printing" as output speed is not the issue
WORDS_COUNT=5_000_0... | true |
fee2660f418ebfc04acfc99600572c9b55799574 | Ruby | aasimalee/my_books | /Full Stack Web Developer/11 - Programming with Ruby/07 - conditional-and-logical-operators-and-program-flow-control/exercices-and-code/grade_range_case_version.rb | UTF-8 | 415 | 3.765625 | 4 | [] | no_license | # File: grade_range_case_version.rb
#
print 'What is the grade? (0 - 10) '
grade = gets.to_f
case
when grade >= 0 && grade <5
puts 'This is a FAIL'
when grade >= 5 && grade < 8
puts 'This is a PASS'
when grade >= 8 && grade < 9
puts 'This is a VERY GOOD'
when grade >=9 && grade <= 10
puts 'This ... | true |
454a0000c3d08d1f26fc04692f39b1bd545010c3 | Ruby | pmazalov/ruby-retrospective-3 | /solutions/01.rb | UTF-8 | 849 | 3.25 | 3 | [] | no_license | class Integer
def prime?
return false if self <= 1
2.upto(pred).all? { |divisor| remainder(divisor).nonzero? }
end
def prime_factors
return [] if abs < 2
divisor = 2.upto(abs).find { |divisor| abs.remainder(divisor).zero? }
[divisor] + (abs / divisor).prime_factors
end
def digits
abs... | true |
6b4ccd50209ff4e353c7f5da0aba7b59b5dd2641 | Ruby | derekpovah/aeries-api | /lib/aeries-api/client.rb | UTF-8 | 1,676 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/keys'
require 'hashie'
require 'aeries-api/client/contacts'
require 'aeries-api/client/schools'
require 'aeries-api/client/students'
require 'aeries-api/client/student_groups'
require 'aeries-api/client/student_pictures'
require... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.