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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b4e45d5450882c55cc7b44cebb04970d2ae60214 | Ruby | dwhitworth/wyza_scripts | /crawl_wyza_galleries.rb | UTF-8 | 1,932 | 2.828125 | 3 | [] | no_license | require 'open-uri'
require 'nokogiri'
def process_html address
counter = 1
content = ''
while counter < 15 do
begin
file = URI.open(address)
document = Nokogiri::HTML.parse(file)
text = document.css('div.slides')
if text
content += tex... | true |
a4814a6f40fb5db16123ffe5b4c1c872a69cab69 | Ruby | ettl02/regex-lab-v-000 | /lib/regex_lab.rb | UTF-8 | 455 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def starts_with_a_vowel?(word)
!!word.capitalize.match(/\A[aeiou]/i)
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/\b[Uu]n[a-z]*ing\b/)
end
def words_five_letters_long(text)
text.scan(/\b\w{5}\b/)
end
def first_word_capitalized_and_ends_with_punctuation?(text)
if text.match(/\A[A-Z].+[.,?!... | true |
8f9943753d21688c6acfbb80cfd5a3c9ab85aa55 | Ruby | wikiti/pbatcher | /lib/pbatcher/proc_handler.rb | UTF-8 | 363 | 2.84375 | 3 | [
"MIT"
] | permissive | module PBatcher
class ProcHandler < Handler
attr_reader :method
def initialize(generator, method = nil, &block)
super(generator)
method = method ? method : block
raise ArgumentError, 'Namer is not a proc' unless method.is_a? Proc
@method = method || block
end
def call(*args)
... | true |
1231bc70073e29038f138aadeeebe95520c6e2cd | Ruby | chef/license_scout | /spec/fixtures/bundler_2x_gems_dir/gems/test-kitchen-1.24.0/lib/kitchen/metadata_chopper.rb | UTF-8 | 1,817 | 2.921875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference",
"CC0-1.0",
"LicenseRef-scancode-free-unknown"
] | permissive | # -*- encoding: utf-8 -*-
#
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
#
# Copyright (C) 2012, Fletcher Nichol
#
# 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.o... | true |
e01f22ee653f6e16a35e09e9e723f218856f88b6 | Ruby | limxn/exercism | /ruby/tournament/tournament.rb | UTF-8 | 2,096 | 3.59375 | 4 | [] | no_license | class Tournament
OPPOSITE = {:win => :loss, :draw => :draw, :loss => :win}
POINTS = {:win => 3, :draw => 1, :loss => 0}
TABLE_PADDING = 31
attr_reader :standings
def self.tally(input)
new(input).print_table
end
def initialize(input)
@standings = Standings.new
process(input)
end
def pro... | true |
3134a33de09719d1156e188d2085594936e31370 | Ruby | jakebellacera/vinery | /test/record_test.rb | UTF-8 | 681 | 2.5625 | 3 | [
"MIT"
] | permissive | require "test_helper"
class RecordTest < MiniTest::Unit::TestCase
def setup
@vinery = Vinery::API.new(ENV["VINE_USERNAME"], ENV["VINE_PASSWORD"])
@record = @vinery.tagged("funny").first
end
def test_to_h
record_hash = @record.to_h
record_attributes.each do |attribute|
assert_equal @record.... | true |
379c4325bc5a9c15e453645c9284f99d0d40e500 | Ruby | KashubaK/RubyTextRPG | /conversation.rb | UTF-8 | 1,827 | 3.359375 | 3 | [] | no_license | # Conversations take place between an NPC and a Player, or an NPC and another NPC
# These can unlock more conversations, turn in quests, require certain skills, etc.
class Conversation
attr_reader :id, :initiator, :target, :options, :current_option_index, :unlocked_options
def initialize(convo)
@initiator = co... | true |
c901e0f5d89bb5f4ec9aae21711bb4484fceedc7 | Ruby | gonz/fiasco | /fiasco/global_state.rb | UTF-8 | 982 | 2.734375 | 3 | [] | no_license | require 'set'
module Fiasco
class GlobalState < BasicObject
def initialize
@__attributes__ = ::Set.new
end
def inspect
values = @__attributes__.inject([]) do |acc, v|
acc << "#{v}=#{__send__(v).inspect}"
end.join(' ')
"<GlobalState #{values}>"
end
# required so t... | true |
fc4f59dfc9601a5ddaa6b915fea6528b3c0e7cb8 | Ruby | austccr/link_and_attachment_archiver | /lib/link_archiver/archive_links.rb | UTF-8 | 1,467 | 2.65625 | 3 | [] | no_license | class LinkArchiver
def archive_links(skipped_saved: false)
links.each_with_index do |link,i|
if skipped_saved
existing_link = ScraperWiki.select(
"* FROM data WHERE url='#{link[:url]}' AND source_url='#{source_url}'"
).last rescue nil
end
if skipped_saved && existing_l... | true |
2ed54a9040b03e96fd19c837256b899f592e498b | Ruby | OtherMichaelDuvall/exercism.io | /ruby/hamming/hamming.rb | UTF-8 | 346 | 3.265625 | 3 | [] | no_license | module BookKeeping
VERSION = 3
end
class Hamming
def self.compute(dna1, dna2)
strand_one, strand_two = dna1.chars ,dna2.chars
raise ArgumentError.new("Sequence lengths differ") unless strand_one.length == strand_two.length
strand_one.zip(strand_two).count { |sequence_one, sequence_two| sequence_one !=... | true |
e26f8099890a2155abbc72590d9d2619829da586 | Ruby | iwabuchiken/WS_Music | /build_list.rb | UTF-8 | 595 | 3.0625 | 3 | [] | no_license | def exec
#ref http://stackoverflow.com/questions/1755665/get-names-of-all-files-from-a-folder-with-ruby answered Nov 18 '09 at 12:44
list = Dir["domino/*"]
list.sort
puts list
# file io
fname = "sample.txt"
somefile = File.open(fname, "a")
# somefile = File.open(fname, "w")
... | true |
7f7bdfa6ced9678cc5a9ed39a17e7676b7db40e7 | Ruby | ada74m/grebe | /spec/models/criteria/or_spec.rb | UTF-8 | 2,215 | 2.53125 | 3 | [] | no_license | require "rspec"
describe "Or criterion" do
it "should be a composite" do
CompositeCriterion.or.should be_a_kind_of CompositeCriterion
end
it "should describe itself" do
criterion = CompositeCriterion.or
criterion.description.should == ''
criterion.children << (Equals.new :model => :ship, :pr... | true |
d0c55dbc293ceff875474ea923837bc0bce99df8 | Ruby | newtypeV2/has_many_template_repo | /location.rb | UTF-8 | 241 | 3.015625 | 3 | [] | no_license | class Location
attr_reader :name
def initialize(name)
@name = name
end
def pokemon
Poke_Loc.all.select{ |join| join.location == self }
end
def pokemon_count
self.pokemon.length
end
end
| true |
955a4c7de6412ff00b0e10b4f3d6329d778fa117 | Ruby | dregules/boris_bikes | /lib/docking_station.rb | UTF-8 | 871 | 3.265625 | 3 | [] | no_license | require_relative 'bike' #irb was modified to require ./lib by default
class DockingStation
DEFAULT_CAPACITY = 20
attr_accessor :capacity
def initialize
@bikes = []
@capacity = DEFAULT_CAPACITY
end
def release_bike
working_bikes = @bikes.select {|bike| bike.working?}
broken_bikes = @b... | true |
814dce1531aeb738337bca82bfacf462705a0189 | Ruby | juanoide/Tutoriales-de-ruby | /Tutoriales de Ruby 2/clsPerro.rb | UTF-8 | 492 | 3.171875 | 3 | [] | no_license | module Mamifero
def respirar
return "sss sss"
end
end
module Carnivoro
def comer(comida)
raise "Los carnivoros solo comen carne" unless comida.kind_of?(Conejo)
puts "Estoy comiendo"
end
end
module Herviboro
def comer(comida)
raise "Los herviboros solo comen hierba" unless comida.kind_of?... | true |
8f1b18f880df4c55d5dbafb2d97a249e4015be07 | Ruby | 3QUB/scrapping | /trader_obscur.rb | UTF-8 | 766 | 3.03125 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'pry'
def count_element (lien_cmc)
doc = Nokogiri::HTML(open(lien_cmc))
currency_list = []
nb_currency = doc.search("tbody/tr").size
i = 1
while i < 10
name = doc.css("tbody/tr[#{i}]/td[2]/a").text #Bitcoin
symbol = doc.css("tbody/tr[#{i}]/... | true |
7ee39102f4de816cd9c3a4382a4a1223b6c3ea39 | Ruby | lian/ver | /lib/ver/vendor/pathname.rb | UTF-8 | 369 | 2.6875 | 3 | [
"MIT"
] | permissive | # annoying fixes
class Pathname
alias / join
def cp(dest)
FileUtils.copy_file(expand_path.to_s, dest.to_s, preserve = true)
end
def =~(regexp)
to_s =~ regexp
end
def glob(&block)
if block
Dir.glob(to_s){|match| yield(self.class.new(match)) }
else
Dir.glob(to_s)
end
end
... | true |
8533687db4df67ace6895291673862e0aea70378 | Ruby | SebNik/Inf-SGH-RUBY | /03-05-10-Kryptographie/caesar.rb | UTF-8 | 429 | 3.828125 | 4 | [] | no_license | # the code is creating the text in ceaser chifere with x
abc = "abcdefghijklmnopqrstuvwxyz"
print "Text: "
text = gets.chomp
print "Schlüssel: "
key = gets.chomp
x = abc.index(key.downcase)
chiffre = abc[x..-1] + abc[0, x]
text = text.tr(abc.downcase+abc.upcase, chiffre.downcase+chiffre.upcase)
print "verschlüsselt: "... | true |
74d3b8a7422528387a75f0de6b1acd594621a993 | Ruby | tomstuart/kanren | /lib/kanren/micro/state.rb | UTF-8 | 1,308 | 3.296875 | 3 | [
"CC0-1.0"
] | permissive | require 'kanren/micro/variable'
require 'kanren/pair'
module Kanren
module Micro
class State
def initialize(variables = [], values = {})
@variables, @values = variables, values
end
attr_reader :variables, :values
def create_variables(names)
new_variables = names.map { |n... | true |
490fb009fad80f63382e4b052b45f561567cc2d3 | Ruby | ssalgado2017/clase11 | /2 ciclos/ejercicio8.rb | UTF-8 | 258 | 3.53125 | 4 | [] | no_license | # Generar -utilizando un ciclo iterativo- un string con la siguiente estructura:
# a = '1impar 2par 3impar 4par 5impar 6par 7impar 8par 9impar 10par'
a = ''
10.times do |i|
i += 1
i = i.to_i
a = i % 2 == 0 ? "#{i}par ": "#{i}impar "
print a
end
| true |
35c2cf8d1e17b4ed49360d0e399338329a305e9d | Ruby | txbluebee/capstone_bl_store | /app/models/cart.rb | UTF-8 | 492 | 2.671875 | 3 | [
"MIT"
] | permissive | class Cart < ApplicationRecord
has_many :cart_items
has_many :products, through: :cart_items, source: :product
def add_product_to_cart(product)
ci = cart_items.build
ci.product = product
ci.quantity = 1
ci.save
end
def total_price
sum = 0
cart_items.each do |cart_item|
if cart... | true |
b3fd0413705b239f8de7eb357cf5eb517c8e8730 | Ruby | abreaux26/enigma | /lib/encrypt.rb | UTF-8 | 377 | 3.0625 | 3 | [] | no_license | require_relative 'enigma'
read_file = File.open(ARGV[0])
write_file = ARGV[1]
message_to_encrypt = read_file.read.chomp
enigma = Enigma.new
encrypted = enigma.encrypt(message_to_encrypt)
encryption = encrypted[:encryption]
key = encrypted[:key]
date = encrypted[:date]
File.write(write_file, encryption)
puts "Creat... | true |
16bf1cea0c0727d579a9c8ed5d66d5638a0a3f5e | Ruby | pedrogglima/scrap-cbf | /lib/scrap_cbf.rb | UTF-8 | 2,965 | 2.703125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'nokogiri'
require 'open-uri'
require 'json'
require 'active_support/core_ext/hash/indifferent_access'
require 'forwardable'
require_relative 'scrap_cbf/errors'
require_relative 'scrap_cbf/formattable'
require_relative 'scrap_cbf/printable'
require_relative 'scrap_cbf/document'
r... | true |
5eb2a8763fce98b74edfac6332f4bdefe2a54198 | Ruby | G5/dxa-automation-script | /derClasses/engImgClass1.rb | UTF-8 | 1,645 | 2.515625 | 3 | [] | no_license | require '../testClasses/testClass1'
class EngImgTest < TestClass
def initialize(requirements, selDriver, nokoPage, scoreCoeff, testNam, fileNam=:DEFINED, logFil=:DEFINED, urlName=:DEFINED, bizNam=:DEFINED, gPlusI=:DEFINED, allLink=:DEFINED, zipCod=:DEFINED)
super(requirements, selDriver, nokoPage, scoreCoeff,... | true |
96ed76c7de9fce3a4e5640ebd8aabf543028cfc2 | Ruby | NenehB/Makersbnb | /lib/account.rb | UTF-8 | 2,273 | 2.984375 | 3 | [] | no_license | require 'pg'
require 'bcrypt'
class Account
attr_reader :id, :name, :login, :password, :host, :signedin, :booking_id
# (id SERIAL PRIMARY KEY, name VARCHAR(60), login VARCHAR(60), password VARCHAR(60), host BIT, signedin BIT, booking_id INTEGER);
def initialize(account)
@account_id = account['id']
@acc... | true |
12f783648c4cfde3c692617c9ddb207530db7726 | Ruby | jan-czekawski/introduction-to-programming-exercises | /more/book_of_ruby/17_threads/file_find.rb | UTF-8 | 761 | 2.984375 | 3 | [] | no_license | require "find"
$total_size = 0
$dir_size = 0
$files = []
$dirs = []
def process_files(base_dir)
Find.find(base_dir) do |path|
$dir_size += $dir_size
if FileTest.directory?(path) && path != base_dir # if directory
$dirs << "#{path} [#{$dir_size / 1024}K]"
$dir_size = 0
else # if file
$f... | true |
9f553dd7b50394f674e7b989cd9541e465b3345c | Ruby | tett23/daisy | /lib/daisy/storage.rb | UTF-8 | 2,446 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'fileutils'
require 'sys/filesystem'
require 'digest/sha1'
module Daisy
class Storage
def initialize(config)
config.deep_symbolize_keys!
@name = config[:name]
@mount_point = config[:mount_point]
case config[:quota][:unit].to_sym
when :bytes
@quota = config[:quota][:... | true |
9e1037cdcf5cbcc437b7883ed349047e8d632584 | Ruby | mkuylman/weather_App | /weather.rb | UTF-8 | 1,029 | 2.875 | 3 | [] | no_license | require 'sinatra'
require 'yahoo_weatherman'
def get_weather(location)
client = Weatherman::Client.new
client.lookup_by_location(location).condition['text']
end
def get_temp(location)
client = Weatherman::Client.new
response = client.lookup_by_location(location).condition['temp']
end
get '/' do
erb :home... | true |
a54121588961c40651a159f2c414623a55ecf7ec | Ruby | joshaber/AXElements | /lib/ax_elements/elements/application.rb | UTF-8 | 2,109 | 2.65625 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # -*- coding: utf-8 -*-
##
# Some additional constructors and conveniences for Application objects.
#
# As this class has evolved, it has gathered some functionality from
# the `NSRunningApplication` class.
class AX::Application < AX::Element
##
# Overridden so that we can also cache the `NSRunningApplication`
... | true |
ca96bdd795c9b1fd3ddda610aba4b8eda651f918 | Ruby | mangyvr/product-api | /app/lib/product_price_formatter.rb | UTF-8 | 132 | 2.5625 | 3 | [] | no_license | class ProductPriceFormatter
def self.format(product:, converted_price:)
product.price = converted_price
product
end
end | true |
61170c3227fad9b785406f167fb80a722f696386 | Ruby | kenoir/blender | /models/blender.rb | UTF-8 | 3,805 | 2.65625 | 3 | [] | no_license | require_relative('../mixin/extractors/juicer_json_content_triples.rb')
require_relative('../mixin/extractors/juicer_json_agent_triples.rb')
require_relative('../mixin/extractors/juicer_json_place_triples.rb')
require_relative('../mixin/extractors/juicer_json_article_triples.rb')
class Blender
require 'rdf'
require... | true |
7638992639b91c7c822f9e9e2f0798261942aba3 | Ruby | MotiejusL/tagging-app | /app/controllers/main_controller.rb | UTF-8 | 1,576 | 2.609375 | 3 | [] | no_license | class MainController < ApplicationController
def index
end
def users_for_img
bestscores = BestScore.where(image_id: params[:id])
usersInfo = []
bestscores.each do |score|
usersInfo.push({name: score.user.name, score: score.score})
end
respond_to do |format|
format.json {render jso... | true |
5ecdad70c1816e3aaf3970a1b1242514404d3e7b | Ruby | samikanza/dungeon_keeper | /app/models/treasure.rb | UTF-8 | 705 | 2.59375 | 3 | [] | no_license | class Treasure < ActiveRecord::Base
belongs_to :dungeon
validates :name, :presence => true,
:length => { :in => 5..300 }
validates :value, :presence => true,
:numericality => {:greater_than_or_equal_to => 101, :only_integer => true}
... | true |
d29d55b2b160b968a07c2dac80ff9e3da19045c3 | Ruby | marcelolynch/ruby-stuff | /chelo/Sueltos/factorial.rb | UTF-8 | 72 | 3.328125 | 3 | [] | no_license | def factorial(n)
(n==0)?1 : n*factorial(n-1)
end
puts factorial(1000) | true |
cc54d12194d3f2ecac21d932569e4250bc9393b5 | Ruby | williamtome/ruby-course | /conceitos/tipos_dados/boolean.rb | UTF-8 | 53 | 2.84375 | 3 | [] | no_license | puts true
puts false
puts true.class
puts false.class | true |
66fecea079817500d36e32619320bd45fc121c52 | Ruby | jsheridanwells/PosterMD-api | /app/lib/json_web_token.rb | UTF-8 | 651 | 2.59375 | 3 | [] | no_license | class JsonWebToken
HMAC_SECRET = Rails.application.secrets.secret_key_base
# create json web token
def self.encode(payload, exp = 24.hours.from_now)
# set expiration
payload[:exp] = exp.to_i
#encode with payload and app secret
JWT.encode(payload, HMAC_SECRET)
end
# check if submitted token i... | true |
12b54ce3449cae160c82b8861879b98c09f2d021 | Ruby | toadkicker/railsstrap | /lib/railsstrap/helpers/glyphicon_helper.rb | UTF-8 | 763 | 2.859375 | 3 | [
"MIT"
] | permissive | require 'railsstrap/helpers/icon_helper'
module Railsstrap
module Helpers
# Displays any of the 200 glyphicons available in Bootstrap.
# @deprecated Use {#icon} instead.
# @see http://glyph.smarticons.co/
# @return [String] the HTML to display a glyphicon.
# @param [#to_s] name the name of the ic... | true |
3e8e1a8d180df902504842c937d45ca8fabd8e55 | Ruby | manik1235/lrthw | /ex12.rb | UTF-8 | 91 | 3.390625 | 3 | [] | no_license | print "Give me money! "
money = gets.chomp.to_f
puts "Here's your change: #{money * 0.10}"
| true |
1d35859c7246bb70b38110664253008d6123b483 | Ruby | factualpidgeon/Project-3 | /Project 3/weather/app/lib/predict.rb | UTF-8 | 542 | 3.046875 | 3 | [] | no_license | require 'matrix'
module Predict
class Pred
def initialize(x, y)
@xs = x
@ys = y
end
def regres()
degree = 1
x_data = @xs.map { |x_i| (0..degree).map { |pow| (x_i**pow).to_f} }
mx = Matrix[*x_data]
my = Matrix.column_vector(@ys)
@coefficients = ((mx.t * mx).inv * mx.t * my).transpose.to_a[0]
end
... | true |
88c5f42be65c13b21b142a100c320b02479fffbc | Ruby | davetron5000/weird-ruby | /weird/lib/weird/anti_if/outcome_handler_no_if_method_buggy.rb | UTF-8 | 302 | 2.796875 | 3 | [
"MIT"
] | permissive | class OutcomeNoIf < Outcome
private
def what_to_call(status)
_,method = [
[ ->(status) { status < 500 }, :call_on_decline ],
[ ->(status) { status == 200 }, :call_on_success ],
].detect { |predicate,_|
predicate.(status)
}
method || :call_on_exception
end
end
| true |
d9977b46619dbce010160f90494d959eac9264d6 | Ruby | gaohongwei/cs | /algorithms/binary/msort.rb | UTF-8 | 884 | 3.25 | 3 | [] | no_license | https://gist.github.com/aspyct/3433278
# Use additional space
def msort(ar,start=0,stop=nil)
stop||=ar.length-1
return if (stop-start)<1
pivot = (start + stop)/2
puts ar[start..stop].to_s
msort(ar,start,pivot)
msort(ar,pivot+1,stop)
merge(ar,start,pivot,stop)
end
def merge(ar,start,pivot,stop)
i=start... | true |
d082c0ec95620cc3b7132f7f4746eeb5a412d01c | Ruby | srorabaugh/ics_bc_s18_2 | /week2/ch07/99_bob.rb | UTF-8 | 652 | 3.796875 | 4 | [] | no_license | bottles = 100
while bottles > 3
puts (bottles-1).to_s + ' bottles of beer on the wall, ' +
(bottles-1).to_s + ' bottles of beer.
Take one down and pass it around, ' + (bottles-2).to_s + ' bottles of beer on the wall.'
bottles = (bottles-1)
end
puts '2 bottles of beer on the wall, 2 bottles of beer.'
puts 'Take one ... | true |
55d46426f757d3a532ec19fa9fd1322d3b13ee77 | Ruby | SwimmerRafa/Software-Design-Architecture | /dsl/src/jankenpon_test.rb | UTF-8 | 6,026 | 2.765625 | 3 | [] | no_license | # Domain-Specific Language Pattern
# Date: 27-Apr-2020
# Authors:
# A01378916 Rafael Moreno Cañas
# A01379896 Erick Bautista Perez
# File: jankenpon_test.rb
require 'minitest/autorun'
require 'stringio'
require 'jankenpon'
#unit class for the jankenpon test.
class JakenponTest < Minitest::Test
... | true |
237265b5c3d0ce1c5533ffa4622a6b02075579f5 | Ruby | dvdpostweb/dvdpost | /vendor/plugins/i18n_db/lib/i18n_db/translation.rb | UTF-8 | 3,301 | 2.5625 | 3 | [] | no_license | class Translation < ActiveRecord::Base
belongs_to :locale
set_table_name "i18n_db_translations"
def validate
unless locale.main?
main_tr = counterpart_in_main
if main_tr && !main_tr.text.blank?
if main_tr.count_macros != count_macros
errors.add("text", "did not preserve macro ... | true |
f0544436b90a8d5a7a2962869cf302dada5e7961 | Ruby | em-torres/learn-bootcamp | /ttt-game-status-bootcamp-prep-001/lib/game_status.rb | UTF-8 | 2,045 | 4.0625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
WIN_COMBINATIONS = [
[0,1,2], # Top Row
[3,4,5], # Middle Row
[6,7,8], # Low Row
[0,3,6], # Right Column
[1,4,7], # Middle Column
[2,5,8], # Left Column
[0,4,8... | true |
4cabf6a85cef40ad596b1bc7a2710bdef39c675f | Ruby | nd2687/localwiki | /class/user_csv.rb | UTF-8 | 443 | 2.546875 | 3 | [] | no_license | require 'natto'
require 'csv'
class UserCsv
class << self
def add(name)
CSV.open("localwiki.csv", "a:UTF-8") do |csv|
return if name =~ %r(^[+-.$()?*/&%!"'_,]+)
return if name =~ /^[-.0-9]+$/
name_length = name.length
score = [-36000.0, -400 * (name_length ** 1.5)].max.to_i
... | true |
23b246d5b6f679d6092c64508f4e57c503e3b6a4 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/b894bfc984b3496fb7b0a2189925390b.rb | UTF-8 | 283 | 3.046875 | 3 | [] | no_license | #
# $File: raindrops.rb,v $
# $Date: 2014/12/29 21:53:53 $
# $Revision: 5422aa43b715 $
#
class Raindrops
@@factors = {
3 => 'Pling',
5 => 'Plang',
7 => 'Plong',
}
def self.convert(n)
@@factors.select{|x,_| n % x == 0}.values.inject(&:+) || n.to_s
end
end
| true |
bc645ec146f57e39487db3c9f747d08f2e0c6df6 | Ruby | jenjiyi/tic-tac-toe-rb-q-000 | /lib/tic_tac_toe.rb | UTF-8 | 3,172 | 4.21875 | 4 | [] | no_license |
# Helper Methods
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]} | #{board[8]} "
end
# code your move method here!
def move (board, input, char = "X")
position... | true |
a99158f6ab7537972082e5fb58c252c10571768c | Ruby | marmalou/IMDB_lab | /start_code/models/star.rb | UTF-8 | 887 | 3.328125 | 3 | [] | no_license | require_relative('../db/sql_runner')
class Star
attr_reader :id
attr_accessor :first_name, :last_name
def initialize(options)
@id = options ["id"].to_i if options ["id"]
@first_name = options ["first_name"]
@last_name = options ["last_name"]
end
def save()
sql = "INSERT INTO stars
(first_name,
second_... | true |
1cfaa5b82ca403f0a013944ba664956f762e1991 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/b5e697ad95a44ff3be631776b73f0fb0.rb | UTF-8 | 666 | 3.796875 | 4 | [] | no_license | class Bob
def hey(arg)
if question?(arg) and not shouting?(arg)
"Sure."
elsif shouting?(arg)
"Woah, chill out!"
elsif arg.delete(' ').empty? # and it was reading so nice
"Fine. Be that way!"
else
"Whatever."
end
end
def clean(arg)
arg.gsub(/([^a-z0-9\s]|\s+ )... | true |
4452201677579972728887532239664509d6bd18 | Ruby | pact-foundation/pact-support | /lib/pact/helpers.rb | UTF-8 | 1,831 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'pact/something_like'
require 'pact/term'
require 'pact/array_like'
# Protected, exposed through Pact.term and Pact.like, and included in Pact::Consumer::RSpec
module Pact
module Helpers
def self.included(base)
base.extend(self)
end
def term arg1, arg2 = nil
case arg1
when Ha... | true |
033252468fdedf95e2551070eb6bfc14690c603b | Ruby | Sl0b/lrthw | /ex7.rb | UTF-8 | 714 | 4.0625 | 4 | [] | no_license | #plein de prints
puts "Mary had a little lamb."
puts "Its fleece was white as #{'snow'}."
puts "And everywhere that Mary went."
puts "It would follow her, what a nice lamb."
#ceci affiche un "." 15 fois
puts "." * 15 # what'd that do?
#ici on definie 16 variables ayant chacune pour valeur une lettre en string
end1 = ... | true |
605c6addd52fd3bd9f2bff09ebab5cbdcb52eaf8 | Ruby | Vince-Cercury/Scem | /app/models/comment_observer.rb | UTF-8 | 5,000 | 2.609375 | 3 | [] | no_license | class CommentObserver < ActiveRecord::Observer
def after_create(comment)
puts "comment observer -> after_create called"
comment.reload
#if the comment is passive and we wanted moderation, send activation email to concerned admins and moderators
# if we don't want moderation, only send notification em... | true |
b499ebf549bc8ef2c7532abba3bac61fc41b3d8b | Ruby | mackenco/Eight_Queens | /queens.rb | UTF-8 | 452 | 3.671875 | 4 | [] | no_license | def run
while true
queens = (0..7).to_a.shuffle
break if check?(queens)
end
display(queens)
end
def check?(pos)
pos.each_with_index do |x,y|
j = y+1
while j < pos.length
return false if (x - pos[j]).abs == (y - j).abs
j += 1
end
end
true
end
def display(pos)
board = Arra... | true |
20aed6936b9cfc6a85804b5da6cfd71e72dd40c6 | Ruby | inoh/slideparts | /lib/slideparts/command.rb | UTF-8 | 804 | 2.59375 | 3 | [
"MIT"
] | permissive | module Slideparts
class Command
class << self
def subclasses
@subclasses ||= []
end
def inherited(base)
subclasses << base
super(base)
end
def slide_template
File.expand_path("../slide_template", File.dirname(__FILE__))
end
def execute... | true |
bc481fd67d049b0ec5554b02305f2a2b43d8df05 | Ruby | gmazelier/mongo-meta-driver | /ruby/spec/bson/string_spec.rb | UTF-8 | 4,253 | 2.671875 | 3 | [] | no_license | # encoding: utf-8
require "spec_helper"
describe BSON::String do
describe "::BSON_TYPE" do
it "returns 0x02" do
expect(String::BSON_TYPE).to eq(2.chr)
end
end
describe "#bson_type" do
it "returns the BSON_TYPE" do
expect("test".bson_type).to eq(String::BSON_TYPE)
end
end
desc... | true |
a7b151a312aa631a4ae02683036bebcb1eb6c821 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/raindrops/116a8b2b084f4350bc3ea25395c5661c.rb | UTF-8 | 454 | 3.40625 | 3 | [] | no_license | class Raindrops
DROPS = {
3 => "Pling",
5 => "Plang",
7 => "Plong"
}
def self.convert(number)
result = ""
DROPS.each { |factor,drop|
result << drop if get_factors(number).include?(factor)
}
result.empty? ? number.to_s : result
end
private
def self.get_factors(number)
... | true |
4d06f3c46a92532ab5d338b3091477ca19ea0bec | Ruby | krypt/FuzzBert | /lib/fuzzbert/rake_task.rb | UTF-8 | 1,374 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'fuzzbert'
require 'rake'
require 'rake/tasklib'
class FuzzBert::RakeTask < ::Rake::TaskLib
include ::Rake::DSL if defined?(::Rake::DSL)
# Name of task.
#
# default:
# :fuzz
attr_accessor :name
# Glob pattern to match files.
#
# default:
# 'fuzz/**/fuzz_*.rb'
attr_accessor :pattern
... | true |
a024c166ab00c41adcb92f3bf7c4f6335682d7fa | Ruby | ethanryan/oo-cash-register-web-031317 | /lib/cash_register.rb | UTF-8 | 1,540 | 3.859375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :cart, :prices
#ITEMS = []
def initialize(discount=nil)
@total = 0
@discount = discount
@cart = [] ###adding this, here and above...
@prices = []
end
# def self.all
# @@all
# end
def add_item(item, price, quantity=1)... | true |
d882af5e25ac98544a26a6698112644626b74be3 | Ruby | kubicue/BEWDHW | /src/bewd_homework/lab_03/todo.rb | UTF-8 | 102 | 3.203125 | 3 | [] | no_license | todo = []
puts "What do you need to do today?"
todo << gets.chomp
todo.each do |item|
puts item
end
| true |
1f79db69613f84e0dc00875c9c15ec21fba63637 | Ruby | monora/rgl | /lib/rgl/condensation.rb | UTF-8 | 1,916 | 3.125 | 3 | [
"Ruby",
"BSD-2-Clause"
] | permissive | require 'rgl/base'
require 'rgl/connected_components'
require 'rgl/implicit'
module RGL
module Graph
# Returns an {ImplicitGraph} where the strongly connected components of
# this graph are condensed into single nodes represented by Set instances
# containing the members of each strongly connected comp... | true |
6c902cb9c7649a988362b8b0acef1f7b48f146e0 | Ruby | needlefall/pseudoconn | /samples/syslog_sample.rb | UTF-8 | 1,245 | 2.71875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# This sample demonstrates the old-skool way to manage connections. It's
# necessary if you need to weave connection data together or inject RST frames.
require 'pseudoconn.rb'
pcap = PseudoConn.pcap do
# Send a partial HTTP connection that gets reset prematurely
tcp1 = connection(:src_ip =... | true |
d5df3d08497b371c7662fa18416a9badfcea5507 | Ruby | DottoDev/DecToBin | /ruby/main.rb | UTF-8 | 473 | 3.78125 | 4 | [] | no_license | def decimalToBinary(decimalNumber)
lengthOfBinary = 0
while (decimalNumber >= 2 ** lengthOfBinary)
lengthOfBinary += 1
end
while (lengthOfBinary >= 0)
if ((2 ** lengthOfBinary) > decimalNumber)
print "0"
else
decimalNumber -= 2 ** lengthOfBinary
print "1"
end
lengthOfBinar... | true |
b61328c912de06559b78a416f6f79b48bed13fae | Ruby | rfenix3/oo-my-pets-v-000 | /lib/cat.rb | UTF-8 | 447 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Cat
attr_accessor :mood
attr_reader :name, :owner # belongs to owner
# code goes here
def initialize(name)
@name = name
@mood = "nervous"
end
def mood
@mood
end
# def owner=(owner) # belongs to owner
# raise AssociationTypeMismatchError, "#{owner.class} received, Owner e... | true |
c803ae5c4ec1a3a19e4d15f6edd24511ba3c7f3f | Ruby | chengguangnan/htmlbeautifier | /lib/htmlbeautifier.rb | UTF-8 | 540 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'htmlbeautifier/builder'
require 'htmlbeautifier/html_parser'
require 'htmlbeautifier/version'
module HtmlBeautifier
# Returns a beautified HTML/HTML+ERB document as a String.
# html must be an object that responds to +#to_s+.
#
# Available options are:
# tab_stops - an integer for the number of spa... | true |
4f5bd2db560c24b39be8881bbf231634114ec4e2 | Ruby | astera/tecc | /citizen428/10/euler10.rb | UTF-8 | 83 | 3.015625 | 3 | [] | no_license | require 'prime'
puts Prime.each(2_000_000).inject(0) { |sum, prime| sum += prime } | true |
91c6975e3be30c7651ed22c1d2df79c49e28f01a | Ruby | SynnisterDomini/Phase-0-DBC | /week-6/nesterd_data_solution.rb | UTF-8 | 1,983 | 3.734375 | 4 | [
"MIT"
] | permissive | # RELEASE 2: NESTED STRUCTURE GOLF
# Hole 1
# Target element: "FORE"
array = [[1,2], ["inner", ["eagle", "par", ["FORE", "hook"]]]]
# attempts:
# ============================================================
# print[1][1][2][0]
# ============================================================
# Hole 2
# Target element... | true |
275c5f91710fc33517213e0eece9187a77614bff | Ruby | SaiedAbbasi/badges-and-schedules-001-prework-web | /conference_badges.rb | UTF-8 | 723 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
"Hello, my name is #{name}."
end
attendees = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def batch_badge_creator(attendees)
attendees.collect {|name| badge_maker(name)}
end
rooms = [1..7]
def assign_rooms(attendees)
room_assignments = []
atte... | true |
99ae60898d9defd1536d8cece71a10ad6d2023fa | Ruby | rpalo/advent-of-code-2017 | /lib/validator.rb | UTF-8 | 431 | 3.046875 | 3 | [] | no_license | # frozen_string_literal: true
# Validates system passphrases
module Validator
def self.no_dupes?(phrase)
words = phrase.split
total = words.size
unique = words.uniq.size
(total - unique).zero?
end
def self.no_anagrams?(phrase)
words = phrase.split
sorted = words.map { |word| word.chars.s... | true |
d599e789d86d40aff3b369a05fff471b9bb4faa2 | Ruby | catpiker5519/thicuoiky-ruby-chinchin | /basic/variables.rb | UTF-8 | 629 | 4.09375 | 4 | [] | no_license | # V A R I A B L E S
=begin
Names are case-sensitive and may begin with:
letters, _
After, may include
letters, numbers,_
Convention says
Start with a lowercase word, then additional words are lowercase separated
by an underscore
ex: my_first_variable
=end
name = "Mike" # Strings
age = 30 # ... | true |
e450d6df925f2e4678327341458e3b6d137eec19 | Ruby | nkeller1/public_library_1911 | /test/library_test.rb | UTF-8 | 2,540 | 2.921875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/author'
require './lib/library'
require './lib/book'
class LibraryTest < Minitest::Test
def test_it_exits
dpl = Library.new("Denver Public Library")
assert_instance_of Library, dpl
end
def test_attributes
dpl = Library.new("Denver P... | true |
4c3fddd600f22ec45cf9084abdc76c57e03e93f9 | Ruby | Papillard/coolendar | /app/helpers/calendar_helper.rb | UTF-8 | 2,408 | 2.859375 | 3 | [] | no_license | module CalendarHelper
def calendar(date = Date.today, &block)
Calendar.new(self, date, block).coolendar
end
class Calendar < Struct.new(:view, :date, :callback)
START_DAY = :monday
HEADER = %w[mon tue wed thu fri sat sun]
delegate :content_tag, to: :view
def coolendar
content_tag ... | true |
6bd3da06a3a282fbd621a937e215116260ba5f5a | Ruby | jei-doubleton/rails-habit-tracker-app | /app/models/my_habit.rb | UTF-8 | 490 | 2.828125 | 3 | [
"MIT"
] | permissive | class MyHabit < ApplicationRecord
belongs_to :user
belongs_to :habit
validates :habit_id, presence: { message: "Whoops, you can't track habits without picking a habit!"}
validates :frequency, presence: { message: "Pick how often you want to do this habit."}
def name
self.habit.name
e... | true |
5badf2fa64ee4a04297783b44daa176f58f24802 | Ruby | nielsadb/dx | /src/from_find.rb | UTF-8 | 720 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'set'
# Expected input on stream is as output by the following command:
# find . -exec stat -f "%T %z %m %N" {} + -exec tag {} +
def parse_stream(stream, idx)
stream.each do |line|
stat = line.match /^([\*\/]?) (\d+) (\d+) (.+)$/
if stat then
idx.touch(
name: stat[4],
size: st... | true |
c32991cecedb53e73a52797493a610a8a6d02712 | Ruby | leon-joel/AtCoder | /Dwango5/a.rb | UTF-8 | 416 | 2.96875 | 3 | [] | no_license | require 'pp'
def gets; ARGF.gets; end
def main
n = gets.chomp.to_i
frames = gets.split.map(&:to_i)
ave = frames.inject(:+).to_f / n
min_dist = 100
min_idx = 1000
frames.each_with_index do |f, idx|
dist = (f - ave).abs
if dist == 0.0
puts idx
return
elsif dist < min_dist
min... | true |
7453e8dea0812d0bd78249bf166e0bada71be5cb | Ruby | mindaslab/solid_ruby_code | /builder_pattern/guitar_builder_pattern.rb | UTF-8 | 3,563 | 3.84375 | 4 | [] | no_license | ####################################################
# The Builder pattern example.
####################################################
# The GuitarBuilder class uses the
# Builder pattern to offer an easier
# method of creating a complex and
# multi-part object, the guitar.
#
# The GuitarBuilder class defines
# all ... | true |
4c7c9fd4b0858dc9df090673552e58c868fe59ba | Ruby | gitter-badger/script | /admin/get_weekdays.rb | UTF-8 | 1,011 | 3.125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby -w
# get_weekdays.rb
# Author: Andy Bettisworth
# Description: Get the weekdays based on current day
require 'date'
$LOAD_PATH.push File.expand_path('../../', __FILE__)
require 'admin/admin'
if __FILE__ == $PROGRAM_NAME
WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'... | true |
9aa189c982927e019f495ae2b1dac76121f37956 | Ruby | samrjenkins/smartpension | /ruby_app/parser/views/base.rb | UTF-8 | 505 | 2.6875 | 3 | [] | no_license | # frozen_string_literal: true
module Parser
module Views
class Base
def self.render(pages)
new(pages).render
end
def initialize(pages)
@pages = pages
end
def render
render_header
render_counts
end
private
attr_reader :pages
... | true |
824d18e304b199f3ecdddb0a4ab41411a77fdfda | Ruby | dannamite/RubyByExample | /half_diamond.rb | UTF-8 | 493 | 3.890625 | 4 | [] | no_license | #Write a program that prints out half of the diamond shape using asterisks.
# *
# **
# ***
# ****
# *****
# ******
# *******
# ********
# *******
# ******
# *****
# ****
# ***
# **
# *
#Solution 1
15.times do |count|
if count < 8
puts "*" * (count + 1)
elsif count >= 8
puts "*" * (15 - count)
end
end
#... | true |
c8e9433e5cce472ef0e52aad67e58e95a7cc5142 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/0f7a73a88fca4bfb95ef76a024bf80f7.rb | UTF-8 | 221 | 3.3125 | 3 | [] | no_license | BILLION_SECONDS_IN_YEARS = 11574
class Gigasecond
attr_reader :date
def initialize(birthdate)
@date = get_anniversary(birthdate)
end
def get_anniversary(birthdate)
birthdate + BILLION_SECONDS_IN_YEARS
end
end
| true |
593dc023ca43f68c9e7ed48cb8f6964c6804a5e4 | Ruby | chennakesava1/practic | /Ruby/Ruby pratice 2.rb | UTF-8 | 117 | 2.859375 | 3 | [] | no_license | puts 4+6 (wron)
puts 4 + 6
puts 4 * 6
puts 100 / 2
puts 10 ** ( exponential "how many times" ) 4
puts 50 % 5 | true |
e86e2b5b21af864c9d4072ad5624f5d1093acf1f | Ruby | n8sb/tealeaf | /intro_to_ruby/week_1/lesson_1-quiz.rb | UTF-8 | 2,014 | 4.875 | 5 | [] | no_license | # Lesson 1
# Quiz
# 1.
# What is the value of a after the below code is executed?
a = 1
b = a
b = 3
puts a # => 1
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# 2.
# What's the difference between an Array and a Hash?
# => An Array contains single inde... | true |
d5989b009113b233809894423d956e66c36cff02 | Ruby | apopheny/RB100 | /greeting.rb | UTF-8 | 76 | 3.390625 | 3 | [] | no_license | def greeting(name)
puts "Hello, " + name + "!"
end
puts greeting("Chris") | true |
6e9ada9b051d25dd4319b679db7398dc80c8f6be | Ruby | Hansuuuuuuuuuu/bato | /bin/bato | UTF-8 | 336 | 2.6875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# encoding: utf-8
require "bato/tagatala"
if pangalan_ng_file = ARGV[0]
tagatala = Bato::Tagatala.new
kodigo = File.read pangalan_ng_file, encoding: 'utf-8'
ruby_kodigo = tagatala.sa_ruby kodigo
eval ruby_kodigo
else
puts <<-EOS
Hindi tinukoy ang file. Ang tamang sintaks ay:
bato file.... | true |
b743f0c09bbb97a672914494171a601f90cccac7 | Ruby | nviennot/candy-crusher | /lib/candy-crusher/item.rb | UTF-8 | 4,283 | 2.890625 | 3 | [] | no_license | require 'set'
class CandyCrusher::Item
attr_accessor :name, :modifiers, :taint, :marked_for_destroy
def initialize(name, *modifiers)
@name = name
@modifiers = Set.new(modifiers)
end
class << self
Dir['assets/*.png'].each do |asset|
image = ChunkyPNG::Image.from_file_retina(asset)
asset... | true |
02f70cca4ba894e172e76de56b8de06cb7609ce8 | Ruby | JoeJoe1989/RubyProjects | /CIT/HW2/test.rb | UTF-8 | 2,260 | 3.40625 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
class WorldFactBook
PAGE_URL = "http://www.cis.upenn.edu/~swapneel/test.html"
def initialize
doc = Nokogiri::HTML(open(PAGE_URL))
filter = "table tr td"
@country_info = doc.css(filter)[0]
p "hello"
end
def get_country_info
@country_info
end
def ... | true |
f67fa1c1fcfea46ddb9f49d73152ddc8853f9cfc | Ruby | Jeevz-app/paylocifier | /spec/paylocifier/model_spec.rb | UTF-8 | 3,978 | 2.578125 | 3 | [
"MIT"
] | permissive | RSpec.describe Paylocifier::Model do
describe 'class' do
subject { described_class }
it { is_expected.to respond_to(:url) }
it { is_expected.to respond_to(:id_alias) }
it { is_expected.to respond_to(:associations) }
class MockedModel < Paylocifier::Model; end
before do
allow_any_insta... | true |
34fb1b1690bc1d42a5f24be14f03b66e14f5e38c | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grains/4685da8284c24042ae1e5a3fa9e22433.rb | UTF-8 | 125 | 3.109375 | 3 | [] | no_license | class Grains
MAX_SQUARES = 64
def square(n)
2**(n - 1)
end
def total
square(MAX_SQUARES + 1) - 1
end
end
| true |
3b218c55dee6ad468c96a81ae1d6e27850c94bc8 | Ruby | fullfatthings/alexa | /lib/alexa/connection.rb | UTF-8 | 3,148 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require "cgi"
require "base64"
require "openssl"
require "digest/sha1"
require "faraday"
require "time"
module Alexa
class Connection
attr_accessor :secret_access_key, :access_key_id
attr_writer :params
RFC_3986_UNRESERVED_CHARS = "-_.~a-zA-Z\\d"
SIGNATURE_ALGORITHM = 'AWS4-HMAC-SHA256'
def ini... | true |
708721a269de77847cf0b8c066bc7a63a5fa328e | Ruby | albertbahia/wdi_june_2014 | /w03/d02/alexander_levine/trainers/lib/trainer.rb | UTF-8 | 324 | 2.859375 | 3 | [] | no_license | require 'active_record'
class Trainer < ActiveRecord::Base
has_and_belongs_to_many :pokemons
def whos_that_trainer
info = "ID: #{id}\n"
info += "Name: #{name}\n"
info += "Age: #{age}\n"
info += "Hometown: #{hometown}\n"
end
def choose_pokemon(poke_array)
self.pokemons = poke_array
end
... | true |
aa346855741758632dd6809ba7d5dbf6ecb8896d | Ruby | nwtgck/Ruby_JavaScript_Style_Object | /js_obj.rb | UTF-8 | 168 | 2.859375 | 3 | [] | no_license | class Hash
def method_missing name, value=nil
if name.match(/=$/)
self[name[0..-2].intern] = value
elsif !name.nil?
self[name]
else
super
end
end
end | true |
ed3e44a14a93112a1016a92624eb7893c4bbfb27 | Ruby | William-R-Wilson/data_structures | /linked_list/test.rb | UTF-8 | 517 | 3.640625 | 4 | [] | no_license | require_relative 'linked_list'
require_relative 'node'
l = LinkedList.new("last")
l.prepend("seconde")
l.prepend("first!")
l.print_each
puts "l.size: " + l.size.to_s
puts "l.head: " + l.head.to_s
puts "l.tail: " + l.tail
puts "at index 3: #{l.at(3)}"
puts "at index 2: #{l.at 2}"
puts "at index 0: #{l.at 0}"
puts l.po... | true |
21692ddcfd8ea6625c039567c18b836820a33cb2 | Ruby | AteroConfigs/with_action | /lib/with_action/with_action.rb | UTF-8 | 945 | 2.546875 | 3 | [
"MIT"
] | permissive | module WithAction
def with_action(*actions)
responder = ActionResponder.new(self)
yield responder if block_given?
actions.each {|a| responder.send(a) }
responder.respond
end
class ActionResponder
def initialize(controller)
@controller = controller
@order, @responses = [], {}
... | true |
33daf19b46c36ffd9d42be5c04bd8e40e4450ff2 | Ruby | Miguel-Enrique13/battleship | /lib/player.rb | UTF-8 | 287 | 2.828125 | 3 | [] | no_license | require './lib/ship'
require './lib/cell'
require './lib/board'
class Player
attr_reader :board, :name, :ships
def initialize(name, board, ships)
@name = name
@ships = ships
@board = board
end
def player_lost?
@ships.all? { |ship| ship.sunk? == true}
end
end
| true |
86e21badacba34fb356d301d422309ac7d84b852 | Ruby | pooya1985/excersise_backup | /conferencemanager.rb | UTF-8 | 459 | 2.734375 | 3 | [] | no_license | require './lib/talk'
require './lib/conference'
filename = ARGV.first
conference = Conference.new
File.open(filename).each do |line|
minutes = line.scan(/lightning|\d+/).first
name = line.gsub(/\s*(lightning|\d+min)$/, '').chomp #strip out everything not the talk name and remove end of line/carrige rtns
... | true |
e6b53a7b7260ec15312c3c1f80c0d001191bd1f2 | Ruby | tkfarazad/6by3-backend | /app/services/actualize_user_plan_type_service.rb | UTF-8 | 978 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
class ActualizeUserPlanTypeService
def call(**params)
subscription = params.fetch(:subscription)
return if subscription.nil?
if subscription.trialing?
actualize_by_subscription(subscription)
else
actualize_by_plan(subscription)
end
end
private
de... | true |
5637d0c6b45042174d256f0fc8a932245749c2ab | Ruby | ama-team/ruby-entity-mapper | /test/suite/integration/mapper/type/builtin/enumerable_type.spec.rb | UTF-8 | 2,514 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../../../../../../lib/ama-entity-mapper/type/builtin/enumerable_type'
require_relative '../../../../../../lib/ama-entity-mapper/path/segment'
require_relative '../../../../../../lib/ama-entity-mapper/error/mapping_error'
klass = ::AMA::Entity::Mapper::Type::BuiltIn::Enu... | true |
eb61bd3815e9a36f774e2bc5d9c1c7dc16bc3e09 | Ruby | angelameyer/homework | /studio_game/game_spec.rb | UTF-8 | 662 | 3.109375 | 3 | [] | no_license | require_relative 'game'
describe Game do
before do
@game = Game.new("Knuckleheads")
@initial_health = 100
@player = Player.new("moe", @initial_health)
@game.add_player(@player)
end
it "if a high number is rolled" do
Die.any_instance.stub(:roll).and_return(5)
@game.play
@player.h... | true |
e4f6cbc6d6a9d6e2db2d30a51495aac3ec2de764 | Ruby | edensongjbs/ruby-oo-practice-relationships-domains-yale-web-yss-052520 | /app/models/airbnb.rb | UTF-8 | 1,418 | 3.171875 | 3 | [] | no_license | class Listing
attr_accessor :city
@@all = []
def initialize(city)
@city=city
@@all << self
end
def trips
Trip.all.select{|trip| trip.listing==self}
end
def guests
trips.map{|trip| trip.guest}.uniq
end
def trip_count
trips.count
end
def ... | true |
1e62babac0c1668bddd111a2488def446ebb282d | Ruby | alysonpaige/challenges | /ruby/image2.rb | UTF-8 | 1,318 | 3.890625 | 4 | [] | no_license | class Image
attr_accessor :img
def initialize(array)
@img = array
end
def output_image
@img.each do |row|
row.each do |pixel|
print pixel
end
puts
end
end
def blur(row_index, col_index)
if row_index != 0
@img[row_index-1][col_index] = 1
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.