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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1d2bd95cae39cedbaa3efdf94c56ad6843c54366 | Ruby | easonhan007/defect_only | /app/models/project.rb | UTF-8 | 828 | 2.515625 | 3 | [] | no_license | class Project < ActiveRecord::Base
attr_accessible :description, :name
has_many :project_members
has_many :members, through: :project_members, source: :user
has_many :defects, through: :members
has_many :field_configs
class << self
def predefined_fields
Defect.predefined_fields
end
end #se... | true |
7a63d00a5626ef482fec8e77c987f6c1e7bcce93 | Ruby | olgamarin/workspace | /rb/eje2/saludar.rb | UTF-8 | 415 | 4 | 4 | [] | no_license | =begin Él objetivo en este reto es crear una función saluda que reciba una cadena nombre y retorne el texto
"Hola [nombre]" donde [nombre] es el valor de la cadena que se recibió por parámetro.
=end
#Ejemplos
#saluda("Viceente") #=> "Hola Vicente"
#saluda("Pablo") #=> "Hola Pablo"
#saluda("") #=> "Hola "
def salud... | true |
7410fc7268b39d3e5f2defae39b413ac51ac7e93 | Ruby | mic-css/mars_rover | /lib/directions/east.rb | UTF-8 | 439 | 3.1875 | 3 | [] | no_license | require_relative 'south'
require_relative 'north'
class East
def initialize(south_klass: South, north_klass: North)
@south_klass = south_klass
@north_klass = north_klass
end
def right
@_south ||= south_klass.new
end
def left
@_north ||= north_klass.new
end
def forward(point, terrain)
... | true |
000f31387d3508f22c6ec03600545da950719856 | Ruby | Unsafepond/Enigma-new | /test/offset_test.rb | UTF-8 | 660 | 3.015625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/offset'
class DateOffsetTest < Minitest::Test
def test_it_exists
offset = DateOffset.new
assert offset
end
def test_it_can_get_current_date_in_UTC
current_date = DateOffset.new
assert_equal current_date.date, Time.new.strftime("%... | true |
7b28a7be81778432a26d8bd68d772ce77b4dedb3 | Ruby | JHallberg5100/phase-0-tracks | /ruby/interation.rb | UTF-8 | 1,069 | 3.921875 | 4 | [] | no_license | def method
puts "Method begin"
louis = "blue"
clark = "green"
yield(louis,clark)
end
method { |louis,clark| puts "My favorite color is #{louis}, but I also like #{clark}"}
array = ["bear", "toucan", "barracuda","cicada"]
life = {
"bear" => "mammal",
"toucan"=> "bird",
"barracuda" => "fish",
"cicada"... | true |
af66b6ac37b0d05fe3c3f3cb88ec049f626efc2e | Ruby | mhoad/Cheapdunk-v2 | /app/models/venue.rb | UTF-8 | 2,298 | 2.625 | 3 | [] | no_license | # == Schema Information
#
# Table name: venues
#
# id :integer not null, primary key
# name :string(255)
# description :text
# street_address :string(255)
# postcode :integer
# suburb :string(255)
# url :string(255)
# email :string(255)
# creat... | true |
51501f36ab7245e97ecde717d4b41e76a7fabd79 | Ruby | mn113/adventofcode2017 | /ruby/10.rb | UTF-8 | 1,077 | 3.25 | 3 | [] | no_license | input1 = [187,254,0,81,169,219,1,190,19,102,255,56,46,32,2,216]
input2 = "187,254,0,81,169,219,1,190,19,102,255,56,46,32,2,216"
ring = (0..255).to_a
pos = 0
skip = 0
extra = [17,31,73,47,23]
input = input2.codepoints.concat(extra) # ascii values incl. commas
p "input", input
64.times do
input.each_with_index do |su... | true |
a09b420e5dc231abe00af74b19f7db09a7a759e7 | Ruby | ms-ati/rumonade | /lib/rumonade/error_handling.rb | UTF-8 | 2,844 | 3.390625 | 3 | [
"MIT"
] | permissive | require "delegate"
module Rumonade
# A partial function is a unary function where the domain does not necessarily include all values.
# The function {#defined_at?} allows to test dynamically if a value is in the domain of the function.
#
# NOTE: This is only here to mimic the Scala library just enough to allo... | true |
2143b67e4401c07a9e9f3bd1f032fe3c2901f8c4 | Ruby | xxx/zillashop | /lib/zillashop/product_result.rb | UTF-8 | 1,972 | 2.71875 | 3 | [
"MIT"
] | permissive | class Zillashop
# @author mpd
# @version 1.0
class ProductResult
attr_accessor :model
# initialize a product that is offered by one or more merchants
#
# @param [Hash] hsh a product result returned from Shopzilla
def initialize(hsh)
@hash = hsh
end
# product images
#
#... | true |
c5c165c1fc8e1fc7666039bf0ab3c94e378d66bc | Ruby | bugsdad05/phase-0-tracks | /ruby/game/6_6_game.rb | UTF-8 | 2,401 | 4.21875 | 4 | [] | no_license | =begin
Define a method that will capture a word from user
input: string, (may need to downcase)
steps: ask for string, 'gets.chomp' split string into array
output: secret word as an array
define a method to capture user guess and compare to 'secret word'
input: string, a single letter (may need to downcase)
... | true |
272d1f7b13215b5c59b0277f99fce6d4ee06708c | Ruby | dream121/ruby_mc | /app/models/concerns/hash_helper.rb | UTF-8 | 1,548 | 2.703125 | 3 | [] | no_license | require 'active_support/concern'
module HashHelper
extend ActiveSupport::Concern
included do
end
def normalize_keys(hash, type = 'string')
hash.reduce({}) do |hash, element|
if type == 'string'
hash.update(element[0].to_s => element[1])
else
hash.update(element[0].to_sym => el... | true |
644cf61b1b7afeca9c4bcbf41953645cb303e55b | Ruby | John-Li/my_programs | /book/arrays/1_dimentional/task-19.rb | UTF-8 | 233 | 3.1875 | 3 | [] | no_license | # Задача 19.
# В массиве из 10 чисел переставить минимальный элемент на последнее место.
def method_19(array)
array.push (array.slice!(array.index(array.min)))
end
| true |
d9f993717fb26bbdbba5c16a970c4c6167b9fbb1 | Ruby | skryl/config_logic | /spec/overlay_spec.rb | UTF-8 | 1,157 | 2.53125 | 3 | [] | no_license | require File.join(File.dirname(__FILE__), "spec_helper.rb")
describe ConfigLogic::Overlay do
before :each do
settings = { :name => :an_overlay, :inputs => [:input1, :input2, :input3] }
@e = ConfigLogic::Overlay.new(settings)
@e.set_input(:input1, {:a => 1})
@e.set_input(:input2, {:b => 2})
@e.s... | true |
666f9a323e2eac5e8473a17cd20eb937086cb1bc | Ruby | Djenan/Drupal-theme-SASS-boilerplate | /sass/svg/svg.rb | UTF-8 | 3,380 | 2.6875 | 3 | [
"MIT"
] | permissive | module SvgFunctions
def svg_convert(width, svgIn, pngOut, pngOut2x, dir1x, dir2x)
assert_type width, :Number
assert_type svgIn, :String
assert_type pngOut, :String
assert_type pngOut2x, :String
assert_type dir1x, :String
assert_type dir2x, :String
svgPath = F... | true |
87b392e173bd5ad527aa9d9fa8df676d0c88beb0 | Ruby | erikbenton/AppAcademyFullStackOnline | /Software Engineering Foundations/RSpec/Exercises/rspec_exercise_1/lib/part_2.rb | UTF-8 | 1,215 | 3.84375 | 4 | [] | no_license | def hipsterfy_me(word)
vowels = "aeiouAEIUO".split("")
word.reverse.each_char.with_index do |char, idx|
if vowels.include?(char)
word[-(idx + 1)] = " "
break
end
end
word.split.join
end
# After watching the solutions
def hipsterfy(word)
vowels = "aeiouAEIUO".split("")
idx = word.length ... | true |
27db101190b39f779e91f1d0b8ef110f13f37eb2 | Ruby | rcuhljr/rosalind | /rosalind_rabbit_fib.rb | UTF-8 | 410 | 2.9375 | 3 | [
"MIT"
] | permissive | def rabbit_fib(months, litter_size)
if(months < 3) then
return 1
end
a, b = 1, 1
(months-2).times {a, b = b, a*litter_size + b }
return b
end
File.open('results.txt', "w") do |output|
File.foreach("rabbit_data.txt") do |line|
datum = line.chomp.scan(/\d+/)
months = datum[0].to_i
lit... | true |
2b86d656d4c648ffd61c6784dfae79e9fcbd3d87 | Ruby | yegor/a-bot-server | /app/entities/game/base/player.rb | UTF-8 | 883 | 2.609375 | 3 | [] | no_license | module Entities
module Game
module Base
class Player
include ::Phoenix::Entity::Base
# Properties defined on this entity (will be sent to clients):
#
# id: int32
#
presence :global
attr_accessor :account
attr_accessor :match
... | true |
ebd72e94d38bf2dfd58525c2dc979e4631aac4ee | Ruby | Batmams/tests-ruby | /lib/01_temperature.rb | UTF-8 | 112 | 3.15625 | 3 | [] | no_license | def ftoc(farenheit)
return (farenheit - 32) * 5/9
end
def ctof(celsius)
return (celsius *1.8) + 32
end
| true |
7093ec3c70fee32cc535c3e3fca6c7147a19fccf | Ruby | senotrusov/rubymq-facets | /lib/rubymq-facets/core/thread.rb | UTF-8 | 2,553 | 2.734375 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | #
# Copyright 2006-2008 Stanislav Senotrusov <senotrusov@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless req... | true |
fcc08ed3316973e6b79919c3c97c9dfc512c7ea0 | Ruby | daytonn/judojs | /tests/project_test.rb | UTF-8 | 5,077 | 2.53125 | 3 | [
"LicenseRef-scancode-compass"
] | permissive | require 'test/unit'
require '../lib/judojs.rb'
class TC_TestProject < Test::Unit::TestCase
def setup
@test_project = Judojs::Project.new('MyApplication', 'js')
@path = File.dirname(__FILE__)
end
def test_can_initialize_project
assert_equal('myapplication', @test_project.app_filename, 'test_proj... | true |
7e585575df9f143cbf97f4c609aa90d08dfe8bd4 | Ruby | jcreiff/exercism | /ruby/raindrops/raindrops.rb | UTF-8 | 219 | 2.859375 | 3 | [] | no_license | class Raindrops
def self.convert(num)
result = NOISES.select { |h, _k| (num % h).zero? }
result.empty? ? num.to_s : result.values.join
end
NOISES = { 3 => 'Pling', 5 => 'Plang', 7 => 'Plong' }.freeze
end
| true |
6271bd196147ea2c85a6f9bc2ae3f00dacf1ff38 | Ruby | oleksandrkits/body-mass-index-calculator | /application.rb | UTF-8 | 211 | 3.03125 | 3 | [] | no_license | require_relative "bmi"
require_relative "input_handler"
input = InputHandler.new
bmi = BMI.new(input.height, input.weight, input.units)
puts "Your body mass index is #{bmi.bmi}, wich means #{bmi.explanation}"
| true |
03c6640e4763d4974aa228bb64c40b83df5bff6e | Ruby | ClareBee/KaraokeBar | /room.rb | UTF-8 | 1,031 | 3.5 | 4 | [] | no_license | class Room
attr_accessor :room_number, :capacity, :playlist, :occupancy
def initialize(room_number, capacity)
@room_number = room_number
@capacity = capacity
@occupancy = []
@playlist = []
end
def check_room_number
return @room_number
end
def check_capacity
return @capacity - @occu... | true |
6dae95d7050dc7252050ef90afa7b8d777649a38 | Ruby | nmoutana/sr | /lib/sr/node.rb | UTF-8 | 542 | 2.75 | 3 | [] | no_license | require "sr"
module Sr
def self.node=(node)
@node = node
end
def self.node
@node
end
class Node
attr_accessor :ipaddr
attr_accessor :fetcher_port, :worker_port, :collector_port
attr_accessor :master_loc, :master_port
attr_accessor :uuid
def master
"#{@master_loc}:#{@maste... | true |
dd89127de2e1c1c86d97dfa2b2d01f18baf01030 | Ruby | theandrewykim/akpj-flash-card- | /app/models/card.rb | UTF-8 | 490 | 2.671875 | 3 | [] | no_license | class Card < ActiveRecord::Base
validates :deck, presence: true
belongs_to :deck
has_many :guesses
def correct_yet?(round)
guesses = Guess.where(round_id: round.id, card_id: self.id)
if guesses.empty?
false
else
guesses.any? {|guess| guess.correct? == true}
end
end
def first_at... | true |
ad3c9eb32652ad3917efe4bcaf645a5b684d2128 | Ruby | Wisunse/Harmonogram | /models/authentication.rb | UTF-8 | 723 | 2.6875 | 3 | [] | no_license | class Authentication
def self.authentication(params = {})
if !params[:login].nil? && !params[:password].nil?
sql = { statement: 'SELECT * FROM accounts where login = $1',
values: [params[:login]] }
result = Tools.sql_query(sql)
if result.count == 1
username = result[0][... | true |
5ce0efb81297a46ced7cf215b8413315b976b563 | Ruby | jgg9026/Ruby-pizza-en-equipo | /find_by_points.rb | UTF-8 | 576 | 3.28125 | 3 | [] | no_license | @file_path= "lista.txt"
def find_by_points(points)
cant = points.to_i
nombre=''
puntos=''
aporte=''
band=false
File.foreach(@file_path){}
tamaño = $. # con esto a tamaño se le asigna el numero de lineas del archivo
if tamaño ==0
puts "File is empty genius"
else
File.foreach(@file_path) do |... | true |
16b4d17ddf60afd07ecc51cb6a9385877a0a9779 | Ruby | rodolfopeixoto/fertilizante | /product.rb | UTF-8 | 2,738 | 3.828125 | 4 | [] | no_license | @products = []
def header
puts "**********************************************"
puts "Digite a opção desejada:"
puts "1) Inserir um Fertilizante"
puts "2) Pesquisar um Fertilizantes por Preço"
puts "3) Editar Preço de um Fertilizante"
puts "4) Sair"
puts "5) Visualizar todos"
puts... | true |
e6252fe62b63f202d93a5a2275f91d37460e3e3b | Ruby | robdrosenberg/news-hunt | /app/models/hacker_news.rb | UTF-8 | 553 | 2.625 | 3 | [] | no_license | require 'unirest'
class HackerNews < ApplicationRecord
def self.get_posts
response = Unirest.get('https://api.hnpwa.com/v0/news/1.json')
posts = response.body[0..19]
posts.map!{|post| normalize(post)}
end
def self.normalize(post)
{
id: post['id'],
title: post['title'],
ur... | true |
cc3b2960f0575e1b449db27d496bde478c31a405 | Ruby | kenta-s/atcoder | /abc117/c01.rb | UTF-8 | 230 | 2.734375 | 3 | [] | no_license | n,m = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
xs.sort!
diff = []
m.times do |i|
break if xs[i+1].nil?
diff << xs[i+1] - xs[i]
end
diff.sort!
(n-1).times do
diff.pop
end
ans = diff.reduce(0){|a,e| a+=e}
puts ans
| true |
03e0c5ebea8221a63325346cc1012e44d1b8a66a | Ruby | joshlarson/advent-of-code-2017 | /day2/checksum.rb | UTF-8 | 746 | 3.578125 | 4 | [] | no_license | class Array
def max
self.reduce(self.first) { |max, x| x > max ? x : max }
end
def min
self.reduce(self.first) { |min, x| x < min ? x : min }
end
def spread
self.max - self.min
end
def sum
self.reduce(0) { |sum, x| x + sum }
end
end
def sum_over_lines(input, &block)
input.split("\n... | true |
1b4db7cb82e1f1132dd680cb46cd4c30b681ea4f | Ruby | rcqls/dyndoc | /lib/dyndoc/V3/plugins/odt/odt.rb | UTF-8 | 3,474 | 2.59375 | 3 | [] | no_license | =begin
TODO:
1) reprendre tous les types de blocs dyn et nettoyer les blocs nécessitant aucune balise xml!
ex: [#r] ... [#rb] ...
%RVERB{
%RVERB}
2) les => ,... sont à modifier dans les calls :{nom()}
3) idem dans les parties R, ruby
4) les fins de ligne, de pages sont aussi à nettoyer
t.content_xml.root.element... | true |
8a2817a4ff8bbb555f60621f231bb79e28be6999 | Ruby | gellieb/workspace | /app_academy/prep-work1/coding-test-2/test_2/stock_picker.rb | UTF-8 | 428 | 3.1875 | 3 | [] | no_license | def stock_picker(arr)
low = 0
max_sum = 0
sum= 0
lowest = 0
highest = 0
while low < (arr.length)
high = 1
while high < (arr.length)
sum = arr[high] - arr[low]
if sum > max_sum
max_sum = sum
lowest = low
highest = high
end
high+=1
end
low+=1... | true |
1f4bd6267a0c8587e5002d1255a7b68f75ff763e | Ruby | adamluzsi/str2duck | /test/test_parse.rb | UTF-8 | 906 | 2.546875 | 3 | [
"MIT"
] | permissive | $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
require "str2duck"
require 'minitest/autorun'
describe 'StringParse' do
specify 'parse objects into the right format' do
{
"2011-03-12" => Date,
"2007-07-20 18:59:27 +0200" => Time,
"2010-10-30 18:02:56 +0200" => Time,
"2012-09-... | true |
3cb73378a7eb0f6c30a98c30db7dbc6632e5a031 | Ruby | ratnamyadav/attendence | /app/models/student.rb | UTF-8 | 834 | 2.578125 | 3 | [] | no_license | class Student < ActiveRecord::Base
attr_accessible :year, :email, :name, :departments_id
validates :name, presence: true
validates :year, presence: true
validates :email, presence: true, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i }, uniqueness: { case_sensitive: false }
validates :departments_id, p... | true |
9c40ba99b00e56e01b1ce9281fcc9e013be0c492 | Ruby | thelazyfox/euler | /p017/solution.rb | UTF-8 | 199 | 2.9375 | 3 | [] | no_license | require 'rubygems'
require 'linguistics'
Linguistics::use(:en)
count = 0
(1..1000).each do |n|
string = n.en.numwords
count += string.count(("a".."z").to_a.join)
end
puts "Solution: #{count}" | true |
441771459f8db9cc5441ea254e940444645d1782 | Ruby | zlu/happitail | /animal.rb | UTF-8 | 754 | 3.1875 | 3 | [] | no_license | class Animal
def initialize(a_name, a_breed, an_age, a_gender, favorite_toys)
@name = a_name
@breed = a_breed
@age = an_age
@gender = a_gender
@favorite_toys = favorite_toys
end
def name
@name
end
def breed
@breed
end
def age
@age
end
def gender
@gender
end
def favorite_toys
@favori... | true |
926afd5a932de1658faf0883b7a4693162c3d2e0 | Ruby | shatterednirvana/appscale | /AppController/lib/app_manager_client.rb | UTF-8 | 5,662 | 2.8125 | 3 | [
"Apache-2.0",
"BSD-3-Clause"
] | permissive | #!/usr/bin/ruby -w
# Programmer: Navraj Chohan <nlake44@gmail.com>
require 'base64'
require 'openssl'
require 'soap/rpc/driver'
require 'timeout'
require 'helperfunctions'
require 'rubygems'
require 'json'
# Number of seconds to wait before timing out when doing a SOAP call.
# This number should be higher than the m... | true |
d14775851f6637305ef50e0e07f9da9b64d45572 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/nucleotide-count/9f172e03690f461cb4c328abd4231e6b.rb | UTF-8 | 705 | 3.484375 | 3 | [] | no_license | class DNA
VALID_NUCLEOTIDES = %w(A C G T U)
DNA_NUCLEOTIDES = VALID_NUCLEOTIDES - %w(U)
VALID_SEQUENCE_REGEX = /[#{DNA_NUCLEOTIDES.join}]/
attr_reader :sequence
def initialize(sequence)
raise ArgumentError if invalid_sequence?(sequence)
@sequence = sequence
end
def count(nucleotide)
raise A... | true |
f41ddac34dd2c37f6658ac926a704ca87d1bdb7b | Ruby | dantrovato/launch-school | /lesson_2/mortgage_calculator.rb | UTF-8 | 1,146 | 3.40625 | 3 | [] | no_license | # COULD NOT FINISH THIS ONE
def prompt(message)
puts "=> #{message}"
end
def is_valid?(input)
input.to_i.to_s == input && input.to_i > 0
end
# GET INPUT AND VALITADE
prompt('Welcome to mortgage calculator')
prompt('Please enter loan amount')
loan_amount = ''
loop do
loan_amount = gets.chomp
if is_valid?(lo... | true |
33a79f6e61527d1adef9a57e64829264728c388a | Ruby | masahito-nagayama/ruby_scrape | /scrape.rb | UTF-8 | 231 | 2.515625 | 3 | [] | no_license | require 'net/http'
def get_from(url)
Net::HTTP.get(URI(url))
end
def write_file(path, text)
File.open(path, 'w') { |file| file.write(text) }
end
write_file('pintnews.html', get_from('https://masayuki14.github.io/pit-news/')) | true |
d0413fd283c6774724d432dcd7149cb54caa9dca | Ruby | collabnix/dockerlabs | /vendor/bundle/ruby/2.6.0/gems/rubocop-0.93.1/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb | UTF-8 | 5,680 | 2.75 | 3 | [
"Apache-2.0",
"CC-BY-NC-4.0",
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
module RuboCop
module Cop
module Layout
# This cop checks the indentation of hanging closing parentheses in
# method calls, method definitions, and grouped expressions. A hanging
# closing parenthesis means `)` preceded by a line break.
#
# @example
... | true |
091075098e10a7b9743228d7c550b3cd623ca53d | Ruby | alexflores/Venta | /lib/tarificador.rb | UTF-8 | 245 | 2.875 | 3 | [] | no_license | class Tarificador
attr_accessor :estrategia_tarificador
def initialize(estrategia)
@estrategia_tarificador=estrategia
end
def cuanto_por(precio, cantidad)
return @estrategia_tarificador.cuanto_por(cantidad, precio)
end
end | true |
870562e16bc66cbeee096f46c5c99a767684620a | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/7208afe1cad64cce8dcf89014ac112b9.rb | UTF-8 | 262 | 3.515625 | 4 | [] | no_license | class Phrase
def initialize(string)
@string = string.downcase.gsub(/[^a-z'\d\s]/, ' ').split
end
def word_count
@counts = {}
@string.each do |word|
@counts[word].nil? ? @counts[word] = 1 : @counts[word] += 1
end
@counts
end
end
| true |
e0bc3d6afa00bff87dcf20fbbbb7d2c380d20435 | Ruby | ChrisCenatie/chisel | /lib/chisel.rb | UTF-8 | 363 | 3.203125 | 3 | [] | no_license | require_relative 'parser'
input = ARGV[0]
output = ARGV[1]
md_file = File.read(input)
md_count = md_file.count("\n") + 1
md_to_html = Parser.new(md_file)
html = md_to_html.to_html
html_line_count = html.count("\n") + 1
html_file = File.open(output,"w")
html_file.write(html)
puts "Converted #{input} (#{md_count} lines... | true |
6d9fdfc533ebc25d6d25399432e9f0d13ff1761f | Ruby | dminster/class-self-idiom-in-Ruby | /.rb | UTF-8 | 1,853 | 4.40625 | 4 | [] | no_license | First, the class << foo syntax opens up foo's singleton class (eigenclass). This allows you to specialise the behaviour of methods called on that specific object.
a = 'foo'
class << a
def inspect
'"bar"'
end
end
a.inspect # => "bar"
a = 'foo' # new object, new singleton class
a.inspect # => "foo"
Now, t... | true |
ef78f309e9d0bb1ff77ebb4fee3b13761e7603e6 | Ruby | mfssanhueza/E6CP2A1 | /1 metodos/ejercicio4.rb | UTF-8 | 296 | 4.40625 | 4 | [] | no_license | # Crear un método que muestre en pantalla un saludo, el método
# debe recibir un parámetro, si ese parámetro es el string "Hola" el
# método debe mostrar en pantalla "Hola Mundo".
def saludo(a)
puts 'Hola Mundo' if a == 'Hola'
puts 'Error' if a!='Hola'
end
puts saludo('Hola')
puts saludo(83)
| true |
da86cff8907fa55e053e2eefb548de605234cb09 | Ruby | larroyo1/backend_mod_1_prework | /final_prep/annotations.rb | UTF-8 | 2,185 | 4.53125 | 5 | [] | no_license | # Add your annotations, line by line, to the code below using code comments.
# Try to focus on using correct technical vocabulary.
# Use the # to create a new comment
# Build a Bear
# defining method build_a_bear
def build_a_bear(name, age, fur, clothes, special_power)
greeting = "Hey partner! My name is #{name} - w... | true |
2549007435ff459bb12020bc42894e6e8590abe3 | Ruby | EricRicketts/LaunchSchool | /exercises/Ruby/challenges/medium1/code/clock.rb | UTF-8 | 525 | 3.59375 | 4 | [] | no_license | class Clock
HOURS = 24
MINUTES = 60
def self.at(hrs=0, mins=0)
Clock.new(hrs, mins)
end
def initialize(hrs, mins)
total_hours = hrs + mins.divmod(MINUTES).first
@hr = total_hours.modulo(HOURS)
@min = mins.modulo(MINUTES)
end
def +(mins)
Clock.new(hr, mins + min)
end
def -(mins)... | true |
2c0da8f43306990038a84e6219e73e78fe2dccf6 | Ruby | kohbis/leetcode | /algorithms/2595.number-of-even-and-odd-bits/solution.rb | UTF-8 | 258 | 3.59375 | 4 | [] | no_license | # @param {Integer} n
# @return {Integer[]}
def even_odd_bit(n)
even, odd = 0, 0
n.to_s(2).chars.reverse.each_with_index do |c, i|
if c == '1'
if i % 2 == 0
even += 1
else
odd += 1
end
end
end
[even, odd]
end
| true |
3045ae684f98fa321040f98bde12beee6cd803fb | Ruby | haydenlangelier/phase-0-tracks | /ruby/santav2.rb | UTF-8 | 1,346 | 3.671875 | 4 | [] | no_license | class Santa
attr_reader :ethnicity
attr_accessor :gender, :age
def initialize(gender,ethnicity,age=0)
puts "Initializing Santa Instance!"
@gender=gender
@ethnicity=ethnicity
@age=age
@reindeer_ranking=["Rudolph", "Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen"]
end
... | true |
09602c19c2d78ba4e6f6fdfb8792d81626bf4bac | Ruby | krzyzak/toy_robot | /lib/toy_robot/position.rb | UTF-8 | 535 | 3.390625 | 3 | [] | no_license | module ToyRobot
class Position
attr_reader :x, :y, :direction
def initialize(x: nil, y: nil, direction: nil)
@x = x
@y = y
@direction = direction
end
def +(other)
to_x, to_y = case other.direction
when :north
[x, y+1]
when :west
[x-1, y]
when... | true |
5c4c9e8a53e02e19912fb776f6bb7e88ce42f3d1 | Ruby | altabyte/rails-auth0 | /lib/auth0/management_api/access_token.rb | UTF-8 | 5,271 | 2.609375 | 3 | [] | no_license | require 'auth0'
require 'rollbar'
module Auth0
module ManagementAPI
# Get an API access token for the Auth0 API.
module AccessToken
# Get a JWT access token for the management API.
#
# @return [String] a valid JWT access token.
#
# @TODO Cache the access token in Redis and only... | true |
9441fa61d77af5c323fd32b659f088b7ef2ebfe4 | Ruby | rose1264/bringing-it-all-together-nyc-web-062518 | /lib/dog.rb | UTF-8 | 1,695 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog
attr_accessor :name, :breed
attr_reader :id
def initialize(id: nil, name: , breed:)
@id = id
@name = name
@breed = breed
end
def self.create_table
sql = <<-SQL
CREATE TABLE IF NOT EXISTS dogs(
id INTEGER PRIMARY KEY,
name TEXT,
breed TEXT
);
SQL
DB[:conn].execute(sql)
en... | true |
0f59b26ea9a9840008a25eaee5d642bf97892966 | Ruby | tdeo/advent_of_code | /2016/test/17.rb | UTF-8 | 719 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
require 'minitest/autorun'
require_relative('../lib/17_two_steps_forward')
describe TwoStepsForward do
before { @k = TwoStepsForward }
def test_part1_0
assert_nil @k.new('hijkl').part1
end
def test_part1_1
assert_equal 'DDRRRD', @k.new('ihgpwlah').part1
end
def tes... | true |
8d939051ee362496f67cd63958ad2546e6497aa2 | Ruby | Felipeandres11/EjerciciosIntroRuby | /mayoredad.rb | UTF-8 | 131 | 3.390625 | 3 | [] | no_license | puts "¿Que edad tienes?"
edad = gets.chomp.to_i
if edad >=18
puts "Eres mayor de edad"
else
puts "ERES UN PENDEJO"
end
| true |
05ecbe4fca02cd880422e8a350ee252d55e00443 | Ruby | pharaonick/ls_101 | /ex/easy5/letter_counter_1.rb | UTF-8 | 1,413 | 4.15625 | 4 | [] | no_license | # PROBLEM (incl input, output, rules)
# Write a method that takes a string with one or more space separated words
# and returns a hash that shows the number of words of different sizes.
# Words consist of any string of characters that do not include a space.
EXAMPLES/TEST CASES
word_sizes('Four score and seven.') ==... | true |
e1c43e6122a123eca444711383d4ff96b15e3ace | Ruby | toshle/ruby-mp3-player | /lib/players/auditeplayer.rb | UTF-8 | 1,610 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'audite'
class AuditePlayer
attr_reader :adapter, :playlist, :current_song_index, :repeat, :playing
def initialize
@adapter = Audite.new
@playing = false
@repeat = false
@current_song_index = 0
@adapter.events.on(:complete) do
@playing = false
play_next true
end
end
... | true |
6df48775d1e1ea5ee7c8492fbd18f0c69f58c8fc | Ruby | ailadson/memory_puzzle | /game.rb | UTF-8 | 1,457 | 4.0625 | 4 | [] | no_license | require './board.rb'
require './humanplayer.rb'
require './computerplayer.rb'
class Game
def initialize
setup_board
setup_player
end
def play
until @board.won?
play_round
end
@board.render
puts "You've won the game!"
end
private
def setup_player
puts "Do you want to wa... | true |
7fa70b27091849e163d43a98437fad78da4f8775 | Ruby | prisonmike7/cartoon-collections-onl01-seng-ft-052620 | /cartoon_collections.rb | UTF-8 | 530 | 3.1875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
def roll_call_dwarves(dwarf_names)
dwarf_names.each_with_index {|name, index| puts "#{index + 1}.*#{name}"}
end
def summon_captain_planet(planeteer_calls)
planeteer_calls.map {|call| call.capitalize + "!"}
end
def long_planeteer_calls(planeteer_calls)
planeteer_calls.map do |call|
return true if call.size >... | true |
a7b175afefd6f50f30a923a599c4f69fae2d0048 | Ruby | mitzimagination/skillcrush-104 | /ruby_challenges/conditionalcolor.rb | UTF-8 | 462 | 3.546875 | 4 | [] | no_license | fav _color = 'blue'
if (fav_color == 'red')
puts "Red like fire!"
elsif (fav_color == 'orange')
puts "Orange like, well...an orange!"
elsif (fav_color == 'yellow')
puts "Yellow like our sun!"
elsif (fav_color == 'green')
puts "Have you been to the Emerald City of Seattle!?"
elsif (fav_color == 'blue')
puts "Blue l... | true |
cff7f70fd35b7d2f4189935beb5255829898aee0 | Ruby | AlMamun-CSE/competitive_programming | /Codeforces/1567C - Carrying Conundrum/gen_random.rb | UTF-8 | 48 | 2.984375 | 3 | [] | no_license | n = 1_000_000
puts n
n.times do |i|
puts i
end | true |
ec38946dd0f0caed59552d86a091416a30737ef4 | Ruby | Stearnzy/backend_mod_1_prework | /day_3/exercises/lrthw_29_if.rb | UTF-8 | 1,372 | 4.25 | 4 | [] | no_license | people = 20
cats = 30
dogs = 15
if people < cats
puts "Too many cats! The world is doomed!"
end
if people > cats
puts "Not many cats! The world is saved!"
end
if people < dogs
puts "The world is drooled on!"
end
if people > dogs
puts "The world is dry!"
end
dogs += 5
if people >= dogs
puts "People are g... | true |
4066fc98454e08ae9eaae5d36e2a2e79a97d357f | Ruby | kstephens/shout_trace | /lib/shout_trace/annotator.rb | UTF-8 | 8,793 | 2.65625 | 3 | [] | no_license | # kurt@cashnetusa.com 2007/03/16
require 'shout_trace'
module ShoutTrace
# Annotator analyizes strings for lines
# matching "file:line" and creates HTML <a href> links that
# drive a localhost ShoutTrace::Server which will intern
# open a file in a programmer's editor.
#
# This is helpful for diagnosing errors in re... | true |
e9a30a7e19d7f8e4641291aaf48f26cd8b1c22b2 | Ruby | dianajohnson13/appacademy-prep | /w3/w3d3/bonus_version/board.rb | UTF-8 | 1,818 | 3.328125 | 3 | [] | no_license | class Board
attr_accessor :grid
def initialize(grid = Board.default_grid)
@grid = grid
end
def self.default_grid
(Array.new(10) {Array.new(10, nil)})
end
def display
display_board = []
grid.each do |row|
display_row = []
row.each do |spot|
case spot
when :x
display_row << :x
... | true |
03183af21ce2ba00bdb42f54d2b9f15d101f39eb | Ruby | kms617/game_time | /trial_method.rb | UTF-8 | 2,414 | 3.6875 | 4 | [] | no_license | ################
# First I need to make an array of the teams and make them unique:
# [Partiots, Broncos, Steelers, Colts]
# Then, I need to turn those teams into keys in an array of hashes.
# [{"Patriots"=>}
# {"Broncos" =>}
# {"Steelers" =>}
# {"Colts" =>}]
#
# Next, I need to iterate through the game_stats hash ... | true |
8a2832ad11dde79e5475e811922454b2219558bd | Ruby | esttres/blackjack | /shoe.rb | UTF-8 | 415 | 3.421875 | 3 | [] | no_license | require_relative 'deck'
class Shoe
attr_accessor :shoe
def initialize
@shoe = []
7.times do
singledeck = Deck.new
singledeck.deck.each do |card|
@shoe << card
end
end
@shoe.shuffle!
end
end
# shoe = Shoe.new... | true |
5e192c58471e4607657f863a990ef94b4c611689 | Ruby | rynomad/sharedearth-net | /app/helpers/pages_helper.rb | UTF-8 | 29,289 | 2.609375 | 3 | [
"Unlicense"
] | permissive | module PagesHelper
#USE SAME METHOD TO DISPLAY MY EVENTS TO ME, AND MY EVENTS TO OTHER PERSON - SECOND PARAMETER INDICATES IF IT IS SHOWN TO OTHER PERSON IF NOT NIL
def event_log_sentence(event_log, person, feed)
@same_person = (person.nil? || (current_user.person == person)) ? true : false
person||= ... | true |
9ed181cb2f0ed70c42b57df8e29da8f70bc5cf43 | Ruby | ctzitzas/tt_robot | /spec/commands/move_spec.rb | UTF-8 | 710 | 2.6875 | 3 | [
"MIT"
] | permissive | require_relative "../../lib/commands/move"
require_relative "../../lib/tt_robot/output"
RSpec.describe Move do
let(:output) { Output.new }
let(:robot) { Robot.new(output) }
let(:move) { described_class.new(robot) }
context "initialization" do
it "should be an instance of move" do
expect(move).to be_... | true |
0369a52bdbe4a23137e946872b575e772ea4b265 | Ruby | tiffanychu/labs | /to_dos/crazy_strings.rb | UTF-8 | 137 | 3.40625 | 3 | [] | no_license | def crazy_strings(first, second)
first.reverse.upcase+" "+second.gsub("s","z").swapcase
end
puts crazy_strings("first", "second")
| true |
4815e169d122dcb5c449ceb5f82f448cc8961f6f | Ruby | HaryRabarijoely/morpion_jeu | /lib/app/game.rb | UTF-8 | 1,791 | 3.671875 | 4 | [] | no_license | class Game
attr_accessor :players, :board
def initialize
@players = []
@board = Board.new
end
# Fonction qui demande le nom des 2 joueurs
def ask_name
puts "Nom du player 1 ?"
print "> "
@players << Player.new(gets.chomp.to_s, "o")
puts "Nom du player 2 ?"
print "> "
@playe... | true |
8561b594e6744fabf40c150daf05fd1b923a3c1d | Ruby | fbrgmn/tests-ruby | /lib/04_simon_says.rb | UTF-8 | 542 | 3.78125 | 4 | [] | no_license | def echo(s)
return s
end
def shout(s)
return s.upcase
end
def repeat(s, n = 2)
return ([s] * n).join(" ")
end
def start_of_word(s, nb)
return s[0..nb-1]
end
def first_word(s)
return s.split(" ").first
end
def titleize(s) # (source: https://stackoverflow.com/a/17635110)
little_words = %w{a an and the or... | true |
b91b2e0abea4f1a8fd8175118358a595f2ce2ece | Ruby | benlangfeld/synchronicity | /spec/countdownlatch_spec.rb | UTF-8 | 3,836 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'minitest/autorun'
require 'synchronicity'
module Synchronicity
describe CountDownLatch do
it "requires a positive count" do
assert_raises(ArgumentError) { CountDownLatch.new(-1) }
end
describe "#wait" do
describe "counting down from 1" do
before do
@latch = CountDo... | true |
9d1412b13c418e079f07a12f74cb593e054b8748 | Ruby | madis/flicket | /lib/flicket/rectangle.rb | UTF-8 | 598 | 3.28125 | 3 | [
"MIT"
] | permissive | module Flicket
class Rectangle
attr_reader :x, :y, :width, :height
def initialize(x=0, y=0, width, height)
@x = x
@y = y
@width = width
@height = height
end
def aspect_ratio
width.to_f / height
end
def landscape?(width, height)
aspect_ratio >= 1
end
... | true |
342e053c88d77a653f4c49611f62de189482cc6f | Ruby | rachtw/course | /STAT604-Computational Statistics in R & Ruby/hw10-mle/binomial/binomial.rb | UTF-8 | 1,032 | 3.421875 | 3 | [] | no_license | require 'log-likelihood'
class Binomial < LogLikelihood
# Override the constructor in the super class (i.e., 'LogLikelihood')
def initialize(data,n_trials)
super([data]) # Put data into an array for capatibility with
# the super class and call the super class'
# const... | true |
585446855619ed3d4caea022e2e12c4edf9e5960 | Ruby | brandong1/learn-co-sandbox | /collaborating_objects.rb | UTF-8 | 1,112 | 4.03125 | 4 | [] | no_license | # The purpose of this MP3 Importer is to take in a list of mp3s and send each mp3 filename to the Song class to make a Song. Let's just focus on the collaboration. Our MP3Importer class will receive a list of filenames that look like this "Drake - Hotline Bling". MP3Importer will then send each of those filenames to th... | true |
b5ec39e829c87ab71d15b6777d5f060aad18389e | Ruby | sxkosone/green_grocer-dc-web-060418 | /grocer.rb | UTF-8 | 2,202 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def consolidate_cart(cart)
# code here
consolidated = {}
cart.each do |item|
item.each do |product, info|
if consolidated.keys.include?(product)
#add count +1
consolidated[product][:count] += 1
else
#add product hash
consolidated[product] = info
... | true |
751a94821825afc0e36db4c3ad410ae466cb8a85 | Ruby | testuser4213/portfolio0 | /app/models/post.rb | UTF-8 | 667 | 2.796875 | 3 | [] | no_license | #
# Post
#
# + title: string
# + body: string
#
class Post < ActiveRecord::Base
has_many :questions, dependent: :destroy
has_many :taggings, dependent: :destroy
has_many :tags, through: :taggings
validates :title, presence: true
validates :body, presence: true
def str_tags=(names)
self.tags = names... | true |
208dce69cfcb9611ab30c4b8abda2f653a1d8794 | Ruby | dbcls/rdf-config | /lib/rdf-config/schema/chart/unknown_node_generator.rb | UTF-8 | 1,143 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'rdf-config/schema/chart/node_element'
class RDFConfig
class Schema
class Chart
class UnknownNodeGenerator
include NodeElement
def initialize(node, pos)
@node = node
@pos = pos
end
def generate
unknown_object_elements
end
... | true |
ff2cb028a65239bbccb5a03ff396feb3144854cf | Ruby | rdllopes/ruby-course | /Exemplos/2-container/classe_de_equivalencia.rb | UTF-8 | 223 | 3.203125 | 3 | [] | no_license | # Esses dois segmentos de código são "equivalentes"
# eles agrupam os números de 1 a 100 em classes de equivalencia de 5
hash = {}; (1..100).each{|i| hash[i%5] ||= []; hash[i%5] += [i]}; hash
(1..100).group_by {|i| i%5} | true |
cd08920e01a28ac34ab87b7f74416df82c3e2b64 | Ruby | afromankenobi/persons_example | /person.rb | UTF-8 | 424 | 3.5 | 4 | [] | no_license | # Class person.
class Person
attr_accessor :name
attr_accessor :last_name
attr_accessor :country
attr_accessor :continent
attr_accessor :gender
def initialize(name = '', last_name = '', country = '', continent = '', gender = '')
@name = name
@last_name = last_name
@country = country
@contin... | true |
5c80e3df30d4705caefbc1590d88b073a7d66f80 | Ruby | dbravman/project-euler | /puzzle23.rb | UTF-8 | 954 | 3.375 | 3 | [] | no_license | class Puzzle23
def initialize(max)
@max = max
@abundants = []
@abundant_sums = []
find_abundant_numbers
find_abundant_sums
p ((1..@max).to_a - @abundant_sums).reduce(:+)
end
def find_abundant_numbers
(1...@max).each do |number|
sum = 0
(1..Math.sqrt(number)).e... | true |
6f91b242298582dcdb43f83b18d4620cb2b360e2 | Ruby | lara/tic-tac-toe | /game_helper_spec.rb | UTF-8 | 1,889 | 2.859375 | 3 | [] | no_license | require_relative './game_helper'
RSpec.describe GameHelper do
context 'standard 3x3 table' do
describe '#calculate_win' do
subject { described_class.new(table).calculate_win }
context 'empty table' do
let(:table) { (1..9).to_a.map(&:to_s) }
specify { expect(subject).to eq(false) }
... | true |
9e229a1bdbb24c1b0fbb34c747ca55fb180fc93e | Ruby | cnxtech/mission-control | /src/recovery.rb | UTF-8 | 2,290 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'rack'
require './src/functions'
# @param text -> text to be parsed
# @return -> undefined
# @postcondition -> session variables are set
def parse_sections(text)
# parse the full post into individual sections
text.scan(
%r{\[\]\(/# MC // section (.*)\)\n((?:.*\n)*?)(?=\[\]\(/# MC // section .... | true |
6ebcc56a8fc0ba1d71ee6c6e0e257f449acd4362 | Ruby | henrytan0705/platform-code-test | /lib/award.rb | UTF-8 | 2,506 | 3.34375 | 3 | [] | no_license | class Award
attr_reader :name
attr_accessor :expires_in, :quality
# Set max and min as class constants no need to initalize for every instance
MAX_QUALITY = 50
MIN_QUALITY = 0
def initialize(name, initial_expires_in, initial_quality)
@name, @expires_in = name, initial_expires_in
... | true |
6e81634d10ddbd7d36c98e3acbada7e509fe8670 | Ruby | BJSherman80/sesac_test | /save_princess/spec/princess_spec.rb | UTF-8 | 493 | 3.125 | 3 | [] | no_license | require 'rspec'
require 'pry'
require './board'
require './princess'
RSpec.describe Princess do
it 'exists' do
board = Board.new(3, ["---", "-m-", "p--"])
princess = Princess.new(board)
expect(princess).to be_an(Princess)
end
it 'has correct mario column and row cords' do
bo... | true |
6bb1bb0787e297b142b45994d2f424df2df3bee5 | Ruby | ajalvarez89/ruby-scraping | /scraping/scraper.rb | UTF-8 | 2,800 | 3.203125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'csv'
class Scraper
DEFAULT_OPTIONS = {
base_url: 'https://colombia.craigslist.org/',
path: 'search/apa?',
parent: {
element: 'ul',
name: 'search-results',
type: 'id'
},
targets: [
{ key: :title, element: 'a', name: 'result-tit... | true |
e9a5b9e6bb3129c5374e02dbeb54e95bf6fb7374 | Ruby | giovannalnc/rails-watch-list | /db/seeds.rb | UTF-8 | 1,120 | 2.59375 | 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 rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
435d386814517d4519b9e332f4af0cf3accd5127 | Ruby | ualbertalib/jupiter | /lib/entity_constraint.rb | UTF-8 | 230 | 2.53125 | 3 | [
"MIT"
] | permissive | class EntityConstraint
def initialize
@entity_list = [
Item.name.underscore.pluralize,
Thesis.name.underscore.pluralize
]
end
def matches?(request)
@entity_list.include? request[:entity]
end
end
| true |
f8095356e36b9a4bc2640cc5642c52654bc479cb | Ruby | sus111/learn_to_program | /ch09-writing-your-own-methods/roman_numerals.rb | UTF-8 | 684 | 3.28125 | 3 | [] | no_license | def roman_numeral num
romannums = ""
arr = num.to_s.split(//).map{ |chr| chr.to_i }
romannums = "M" * arr[-4] if arr[-4]
if arr[-3] == 9
romannums += "CM"
elsif arr[-3] == 4
romannums += "CD"
else
romannums += "D" * (num % 1000/500)
romannums += "C" * (num % 500/100)
end
if arr[-2... | true |
9dd0427c84148898c9597ab0e179c51c1ab93cd2 | Ruby | mgsullivan/Selenium_cooking_with_Ruby | /Tests/ChapterFour.rb | UTF-8 | 2,160 | 2.796875 | 3 | [] | no_license | require "selenium-webdriver"
require "test/unit"
require "rubygems"
require "CSV"
#Roo was causing problems, so I went with CSV
class TestChapterFour < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :firefox
@testName = "ChapterFour"
end
def test_recipe_eight
test_executed = 0
... | true |
ac2adad9728f7f485dd4ed7693fa87b0e4c4d16a | Ruby | JayachandranArumugam/sample_app | /app/models/user.rb | UTF-8 | 1,970 | 2.640625 | 3 | [] | no_license | require 'digest'
class User < ActiveRecord::Base
has_many :microposts, :dependent => :destroy
has_many :relationships, :foreign_key => "follower_id",:dependent => :destroy
has_many :following, :through => :relationships, :source => :followed
has_many :reverse_relationships, :foreign_key => "followed_id",:class_... | true |
b025d8759f26be1734afb41f0eab2b93dd3452a3 | Ruby | pmoldavski/pulp_fiction | /init.rb | UTF-8 | 620 | 2.53125 | 3 | [] | no_license | require_relative 'movie_quotes'
require_relative 'quote'
require_relative 'database'
require 'twitter'
# Database.create
def load_from_imdb
MovieQuotes.from_imdb('test_scrape.html')
end
def load_from_db
MovieQuotes.from_db
end
def rand_quote_from_db
load_from_db.quotes.sample
end
# load_from_imdb.save_all
# ... | true |
1ddd5d790fccd42bb76eb043c8af2165578fb768 | Ruby | gemini2gemini/ruby_study | /day1/begin.rb | UTF-8 | 83 | 3.140625 | 3 | [] | no_license | def div(z,y)
puts z/y
rescue zeroDivisionError
puts 0
end
div(20,4)
div(20/0)
| true |
ccf81abcf4f4b9063993567a1f9e880ee636c891 | Ruby | yogsototh/euler | /old-ruby/007.rb | UTF-8 | 521 | 3.953125 | 4 | [] | no_license | class NthPrime
def initialize
@t=[]
end
def is_prime(n)
@t.each do |x|
return false if n % x == 0
end
return true
end
def findXthPrime(x)
i=2
while @t.length<x
if is_prime(i)
@t<<=i
puts %{... | true |
8254c36cc521984b6ac54de8572227fc4703f6a0 | Ruby | fresham/old-dotfiles | /bin/socks | UTF-8 | 1,554 | 2.796875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'fileutils'
@port = 8000
@pidfile = File.join( '/', 'tmp', 'socks_sshd.pid' )
@identity_file = File.join( ENV['HOME'], '.ssh', 'EC2.pem' )
@default_location = 'Default'
@socks_location = 'SOCKS Proxy'
def start_daemon
return if status == :on
new_pid = spawn( "ssh -D #{@port} -CqN ubun... | true |
64a5c093309d5ef45d445420d16b7279ba9e4e61 | Ruby | Freshly/spicerack | /technologic/lib/technologic/rspec/shared_examples/a_warn_event_is_logged.rb | UTF-8 | 778 | 2.53125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# RSpec example that tests usage of `#warn`
#
# class Klass
# include Technologic
#
# def initialize(user)
# @user = user
# end
#
# def do_a_thing
# warn :thing_being_done, user: @user
# end
# end
#
# RSpec.describe Klass do
# ... | true |
4204e0af80def6e62aac764b1bbc1dba1335bda4 | Ruby | sparkzilla/week_01_weekend_homework_pet_shop_arrays_hashes | /pet_shop_prints.rb | UTF-8 | 3,793 | 3.40625 | 3 | [] | no_license |
customers = [
{
name: "Alice",
pets: [],
cash: 1000
},
{
name: "Bob",
pets: [],
cash: 50
},
{
name: "Jack",
pets: [],
cash: 100
}
]
new_pet = {
name: "Bors the Younger",
pet_type: :cat,
breed: "Cornish Rex",
price: 100... | true |
7f8a019f7c0d860a54ee72fa07b3abf6fcc48af0 | Ruby | ConnorMarble-zz/deli-counter-001-prework-web | /deli_counter.rb | UTF-8 | 928 | 4.09375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
katz_deli = []
other_deli = ["Logan", "Avi", "Spencer"]
def line(katz_deli)
if katz_deli.size == 0
puts "The line is currently empty."
else
#string to build upon for output
line_message = "The line is currently: "
#iterate over each item in the given ar... | true |
38dcfa3dac9bbf4b918912e59bc2c68ffdb8727e | Ruby | Leninner/ruby_projects | /Variados/romanos_recursivos.rb | UTF-8 | 818 | 3.25 | 3 | [] | no_license | roman_mapping = {
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",
40 => "XL",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I"
}
# Tengo que recorrer por cada llave del hash para poder ir insertando los valores a nuestro pará... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.