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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
3c6e953dbc1e8cc36b2ba3c702fac9253b68c78b | Ruby | festinalent3/learn_to_program | /ch11-reading-and-writing/build_a_better_playlist.rb | UTF-8 | 2,405 | 3.953125 | 4 | [] | no_license | def music_shuffle filenames
filenames_2 = filenames.dup
total_length = filenames.length
((total_length)/2).times { filenames.pop }
filenames_2 = (filenames_2.drop(filenames.length))
filenames = filenames.reverse
shuffle = []
((total_length/2)+1).times do
shuffle << filenames_2.pop unless filenames_2.length == 0
... | true |
d51d3c18f85e08720b3d9f15e3e1bc14ebf19a81 | Ruby | vipulnsward/rbnacl | /lib/rbnacl/keys/verify_key.rb | UTF-8 | 3,777 | 2.9375 | 3 | [
"MIT"
] | permissive | # encoding: binary
module Crypto
# The signature was forged or otherwise corrupt
class BadSignatureError < CryptoError; end
# The public key counterpart to an Ed25519 SigningKey for producing digital
# signatures. Like the name says, VerifyKeys can be used to verify that a
# given digital signature is authen... | true |
220195bddb9d190bf2c1e02f2b5e3b1c87e52315 | Ruby | thefonso/UNCLEFONSO_lessons | /00-week/ruby_basics/07_classes/08-self.rb | UTF-8 | 338 | 3.671875 | 4 | [
"MIT"
] | permissive | # CLASSES: self
#
# At any given time in Ruby, you are in the context
# of some object. Right now we're in the main object.
# Which all of ruby lives under.
# You can see what object you're in by looking at self.
self # => main
class String
self # => String
end
class Example
self # => Example
@abc = 123
@... | true |
3fa4f8a68013f645d1ff2d569aba61bd3c8c8475 | Ruby | deborahchua/bitmap-editor | /spec/bitmap_editor/commands/fill_region_spec.rb | UTF-8 | 3,543 | 3.015625 | 3 | [] | no_license | require 'spec_helper'
require 'pry'
module BitmapEditor
module Commands
RSpec.describe FillRegion do
let(:bitmap) { Bitmap.new(4, 4)}
def expected_equal_bitmap(bitmap, expected)
expected.each_with_index do |row, x|
row.each_with_index do |column, y|
expect(bitmap.get(x,... | true |
6ee4aa59cb632b13033d1ce52eb15c1fe5c345d4 | Ruby | gakio12/Ruby | /comparisons/forEachLoop/for_each.rb | UTF-8 | 201 | 4.3125 | 4 | [] | no_license | # This is a for each loop in Ruby, also known as an
# each iterator.
# Usage: $ ruby for_each.rb
# Prints each element of the array on a new line
i = [0, 1, 2, 3, 4, 5]
i.each do |x|
puts(x)
end | true |
ba4405138570392ad41c6cd6221f5dd20723ee24 | Ruby | ISSIntel/brcobranca | /lib/brcobranca/boleto/banpara.rb | UTF-8 | 3,525 | 2.859375 | 3 | [
"MIT"
] | permissive | # -*- encoding: utf-8 -*-
#
module Brcobranca
module Boleto
class Banpara < Base # Banco BANPARA
validates_length_of :agencia, maximum: 4, message: 'deve ser menor ou igual a 4 dígitos.'
validates_length_of :numero_documento, maximum: 11, message: 'deve ser menor ou igual a 11 dígitos.'
validate... | true |
3b51a38127aef9625488db3442c70689a020e433 | Ruby | wthompson92/battleship | /lib/battleship_runner.rb | UTF-8 | 864 | 3.21875 | 3 | [] | no_license | require './lib/cell'
require './lib/board'
require './lib/ship'
require './lib/messages'
require './lib/turn'
require 'pry'
message = Messages.new
message.main_menu
input = gets.chomp
if input == "q"
print "\nLeaving Battleship\n"
end
while input == "p"
loop do
cruiser = Ship.new("Cruiser", 3)
submarine = S... | true |
6d3e516791c8f1431f37f97852053254a2fbc703 | Ruby | yusabana-sandbox/power-asert-sample | /cli/lib/hoge.rb | UTF-8 | 93 | 2.53125 | 3 | [] | no_license | class Hoge
def initialize(data)
@data = data
end
def get_data
@data
end
end
| true |
9bc5904d3342c2df481df86314051861e64cd4d5 | Ruby | robot-c0der/tankulator | /lib/tankulator/parsers/yamlfileparser.rb | UTF-8 | 1,212 | 2.90625 | 3 | [
"MIT"
] | permissive | module Tankulator
module Parsers
require 'date'
require 'yaml'
class YAMLFileParser < Parser
def initialize_with_filename(filename)
if File.exists?(filename)
if File.readable?(filename)
@input_yaml = Psych.load(File.open(filename))
else
puts "Can't read file! Please make sure it is ... | true |
9b5f90a64dc2a11a8181f6a6ad75a992e00394d7 | Ruby | mthssdrbrg/mpd-rb | /lib/mpd/io/connection.rb | UTF-8 | 1,346 | 2.828125 | 3 | [] | no_license | # encoding: utf-8
require 'socket'
module MPD
module Io
class Connection
attr_reader :version
def initialize(socket_impl = TCPSocket)
@socket_impl = socket_impl
@connected = false
end
def connect(host, port)
if @socket
@socket.close unless @socket.clo... | true |
ff5bd7b9eb436cc3691038524dbb9e5945dde9b3 | Ruby | evo2013/TDD | /triangle/triangle.rb | UTF-8 | 877 | 3.765625 | 4 | [] | no_license | class TriangleError < ArgumentError
end
class Triangle
def initialize(side1, side2, side3)
@side1 = side1
@side2 = side2
@side3 = side3
raise TriangleError.new('Error! Triangle sides must be greater than zero.') if @side1 == 0 || @side2 == 0 || @side3 == 0
raise TriangleError.new('Error! Triangle... | true |
c5e47a1affb25d100fefccfb241c0151b43d1e02 | Ruby | abrysov/mydreams_all_gits | /md-main/app/services/calculate_invoice_total.rb | UTF-8 | 1,033 | 2.671875 | 3 | [] | no_license | class CalculateInvoiceTotal
SPECIAL_DREAMERS = ['jetblackmeerkat@gmail.com']
attr_accessor :invoice
def initialize(invoice, current_dreamer: nil)
@invoice = invoice
@current_dreamer = current_dreamer
end
def call
case invoice.payment_type
when Invoice::VIP_SELF_TYPE, Invoice::VIP_GIFT_TYPE
... | true |
73d5ef859247ce1d81e484a31bdd9446e5810821 | Ruby | BeshoyAtef/Terasoft_14 | /Shipme_proj/spec/models/requests_spec.rb | UTF-8 | 788 | 2.53125 | 3 | [] | no_license | require 'spec_helper'
require 'requests'
#Author: Manar A. Eltayeb.
describe Requests do
it "request is send and saved in the database" do
first_request = Requests.new(accept: 'null' , carriers_id: '24', senders_id: '21',packages_id: '51')
second_request = Requests.new(accept: 'null', carriers_id:'26', senders_id: '... | true |
d7196bcf730e6ef04f9c118e3679ae1bec4ab74b | Ruby | ForwardFinancing/wayback_gem | /lib/wayback/client.rb | UTF-8 | 2,235 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'faraday'
require 'wayback/api/archive'
require 'wayback/configurable'
require 'wayback/error/client_error'
require 'wayback/error/decode_error'
require 'uri'
module Wayback
# Wrapper for the Wayback Memento/Timehop API
class Client
include Wayback::API::Archive
include Wayback::Configurable
#... | true |
832afdc365726b4f80ab4e78afa06306f37dccc1 | Ruby | berniechiu/edX_ESaaS_chapter_three_projects | /project_3.8.rb | UTF-8 | 730 | 4.375 | 4 | [] | no_license | class FibSequence
include Enumerable
def initialize(max)
@fib_nums = [1, 1]
if max > 2
index = 2
while index != max
@fib_nums << @fib_nums[index - 1] + @fib_nums[index - 2]
index += 1
end
elsif max > 0 && max <= 2
@fib_nums = @fib_nums[0..max]
else
@fi... | true |
c556181783c037d4002a3d5148710074bb1391d9 | Ruby | brodiemadden/101-Foundations | /small_problems/easy_5/q8.rb | UTF-8 | 313 | 3.171875 | 3 | [] | no_license | NUMBER_WORDS = %w(zero one two three four
five six seven eight nine
ten eleven twelve thirteen
fourteen fifteen sixteen
seventeen eighteen nineteen)
def alphabetic_number_sort(numbers)
numbers.sort_by { |number| NUMBER_WORDS[number]}
end
| true |
91696730580144fae7a9a95a57358f11813a06d9 | Ruby | Vicks2010/Footy_lge_App | /footy_lge_app/db/seed.rb | UTF-8 | 955 | 2.640625 | 3 | [] | no_license | require('pry-byebug')
require_relative('../models/league.rb')
require_relative('../models/match.rb')
require_relative('../models/team_match.rb')
require_relative('../models/team.rb')
# Team.delete_all()
team1 = Team.new("name"=> "Dukes", "league"=> "Ozzy1")
team1.save()
team2 = Team.new("name"=> "Chiefs", "league"=>... | true |
fa5460aeb786eb4b40549aaef00845701f84d1dd | Ruby | Kristina-D/RubySamurai | /Lesson_8_2/station.rb | UTF-8 | 907 | 3.109375 | 3 | [] | no_license | require_relative 'instance_counter'
require_relative 'instance_validation'
class Station
attr_reader :name, :stations
include InstanceCounter
include Validation
@@stations = []
def initialize(name)
@station_name = name
validate!
@station_trains = []
@@stations << self
register_instance... | true |
81f144086581e13db067f4f1096431ef16c40004 | Ruby | rgo/adventofcode-2020 | /03-toboggan-trajectory/toboggan.rb | UTF-8 | 351 | 3.203125 | 3 | [] | no_license | #!/usr/bin/env ruby
# frozen_string_literal: true
class Toboggan
attr_reader :tree_hits
def initialize(x: 0, y: 0)
@position = { x: x, y: y }
@tree_hits = 0
end
def slide(x: 3, y: 1)
@position[:x] += x
@position[:y] += y
@position
end
def location
@position
end
def hit_tree... | true |
31860c3d894d78aff7c292be882798efe2c98ba3 | Ruby | CrossRef/tinypub | /vendor/bundle/ruby/1.9.1/gems/mongo-1.8.4/test/bson/timestamp_test.rb | UTF-8 | 1,214 | 2.90625 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | require 'test_helper'
class TimestampTest < Test::Unit::TestCase
def test_timestamp_to_s
t1 = Timestamp.new(5000, 200)
assert_equal "seconds: 5000, increment: 200", t1.to_s
end
def test_timestamp_equality
t1 = Timestamp.new(5000, 200)
t2 = Timestamp.new(5000, 200)
assert_equal t2, t1
end
... | true |
9c990a32b0a1f6dd86904d3c64f592a5306216de | Ruby | Siriondil0/Jour2semaine3 | /main.rb | UTF-8 | 906 | 3.421875 | 3 | [] | no_license | # frozen_string_literal: true
require 'bundler'
Bundler.require
$:.unshift File.expand_path("./../lib", __FILE__)
require 'tictactoe.rb'
require "pry"
require "rubocop"
class Perform
# demande le nom des joueurs
def ask_name
puts "Bienvenue dans ce jeu de morpions. Il se joue à deux. Veuillez entrer chacun vot... | true |
4eed3b3e5452c8bc40049a3d3f09d465b68b1604 | Ruby | Jenna424/movement-mixer | /app/models/concerns/sluggable.rb | UTF-8 | 747 | 3.4375 | 3 | [
"MIT"
] | permissive | module Sluggable
module InstanceMethods
def generate_slug # returns slugged version of instance's @name attribute value
name.downcase.gsub(" ", "-") # call #name instance getter on instance (self) to return its @name attribute and then
end # make @name value all lowercase and replace any spaces with hy... | true |
6928a7923a8fb052f97b1fa139a67f2df28e47b5 | Ruby | councilforeconed/vertical-response-to-blue-state | /lib/output-formatter.rb | UTF-8 | 141 | 3.09375 | 3 | [] | no_license | class Output
def initialize
@data = []
end
def <<(row)
@data << row
end
def to_s
@data.join("\n")
end
end | true |
63ffa41c62955ddf049f1d272c32f517bb104f62 | Ruby | tachyons/products-service | /app/queries/products_query.rb | UTF-8 | 765 | 2.53125 | 3 | [
"MIT"
] | permissive | class ProductsQuery
attr_reader :relation
DEFAULT_ENTRIES_PER_PAGE = 6
delegate :to_a, to: :relation
def initialize(relation = Product.all)
@relation = relation
end
def paginate(page = 1, per_page = DEFAULT_ENTRIES_PER_PAGE)
ProductsQuery.new(relation.page(page).per(per_page))
end
def search(q... | true |
d11a762d9992742217c2b89dd5959dd53473d286 | Ruby | GXSRollStream/cruisecontrol.rb-contrib | /plugins/irc_notifier/vendor/ircguerilla-irc-1.3.0/lib/irc/messages/message.rb | UTF-8 | 4,507 | 3.125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without li... | true |
ca31e9202a10d8a146e7c9d337a5c9e19bb7d0ea | Ruby | lech-kopec/Portfolio | /testing_stuff.rb | UTF-8 | 218 | 3.1875 | 3 | [] | no_license | def solution(x, a)
max = 0
count = [0]*(x+1)
a.each_with_index do |z,i|
count[z] += 1 if z <= x
if z<=x && count[z] < 2
max = max<i ? i : max
end
end
max
end | true |
9ee420b6f4576434aa66788c2a488cc9ecd8cb6a | Ruby | ohler55/ox | /test/weather/wox.rb | UTF-8 | 538 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'time'
require 'ox'
module Weather
class WOx
def self.parse(filename, as_time)
highs = {}
doc = Ox.load_file(filename)
table = doc.locate('Workbook/Worksheet/Table')[0]
table.nodes[19..-1].each do |row| # skips Column elements and first Row
t = row.nodes[1].nodes[0].nodes[... | true |
5255c5aba6a3800514664a6aea424864c4d7bfa7 | Ruby | tylteng/ruby_fundamentals2 | /exercise7.rb | UTF-8 | 200 | 3.40625 | 3 | [] | no_license |
def wrap_text(t, s)
return s + t + s
end
puts "Please type some text you would like to be wrapped!!"
s = "###"
t = "==="
u = "---"
n = gets.chomp
puts wrap_text(wrap_text(wrap_text(n, s),t),u)
| true |
9636db725b787c31f379334ba427188a90f9fff1 | Ruby | BohanHsu/leetcode | /test/test_remove_duplicates_from_sorted_list.rb | UTF-8 | 1,406 | 3.46875 | 3 | [] | no_license | require 'minitest/autorun'
require '../remove_duplicates_from_sorted_list.rb'
def list_to_array(head)
arr = []
while !head.nil? do
arr << head.val
head = head.next
end
arr
end
def array_to_list(arr)
head = nil
tail = head
arr.each do |e|
if tail.nil?
tail = ListNode.new e
head = ... | true |
e100dfa899eca3214e6046bd09cced47c3029600 | Ruby | chrischavarro/ironhack-pt | /module2/week5/531_calc/lib/squatcalc.rb | UTF-8 | 73 | 2.6875 | 3 | [] | no_license | class SquatCalculator
def multiply(percent)
@squat * percent
end
end | true |
89702090d74197a7176451dc4646102627853b87 | Ruby | yevdyko/toy-robot | /spec/table_spec.rb | UTF-8 | 1,948 | 2.875 | 3 | [] | no_license | # frozen_string_literal: true
require 'table'
describe Table do
subject(:table) { described_class.new }
describe '#initialize' do
it 'has a default width value' do
expect(table.width).to eq(5)
end
it 'has a default length value' do
expect(table.length).to eq(5)
end
end
describe ... | true |
c0dac6f753ab571fab24c7f98e53f440641eba23 | Ruby | laserylee/sample_app | /test/models/user_test.rb | UTF-8 | 2,464 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Beerware"
] | permissive | require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.create(name:"Example Aser",
email:"example_aser@gmail.com",
password:"foobar",
password_confirmation:"foobar")
end
test "should get valid" do
ass... | true |
e8db1d437d2d4145c8c23c6807ea1084b8b72c7b | Ruby | mtgrosser/bandrip | /bandrip.rb | UTF-8 | 4,736 | 2.734375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# bandrip.rb v0.3.0
# 2020-10-30
require 'uri'
require 'net/http'
require 'json'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'nokogiri'
gem 'http-cookie'
end
class Bandrip
VERSION = '0.3.0'
USER_AGENT = 'Mozilla/5.0 (Android; Mobile; rv:40.0) Gecko/40.0 Firefo... | true |
9858352928611971454ab59f52bab5c83bc66c21 | Ruby | aleksanderbrymora/sei-36 | /harish_ramesh/4week/9march/class/classcode/sei-36-master 9march/05-ruby/conditionals/age.rb | UTF-8 | 135 | 3.765625 | 4 | [] | no_license | print "What is your age: "
age = gets.to_i
if age < 18
puts "You are not old enough to drink."
else
puts "You are good to go"
end
| true |
33d7bbd171d8a345ada2f973ab65e6d088344479 | Ruby | jonathanIvorBetts/ruby101 | /4_standard_types/standard_types.rb | UTF-8 | 2,467 | 4.09375 | 4 | [] | no_license |
### no boolean in ruby, object instead...
TrueClass
Falseclass
# e.g.
true.to_s # "true" to string
false.nil? # false because false insn't nil (it's a thing)
### int - fixnum and bignum
# type converted on the fly by ruby depending how big / small they are
# hex 0x... hex
# oct 0o... octa
# bin 0b... binary
# d... | true |
de0aab63f3f0552bc93aa58b0effe25a4db8a74e | Ruby | danwagnerco/ps-events-rails-i | /app/models/event.rb | UTF-8 | 845 | 2.515625 | 3 | [] | no_license | class Event < ActiveRecord::Base
validates :name, :description, :location, :presence => true
validates :description, :length => {:minimum => 25}
validates :price, :numericality => {:greater_than_or_equal_to => 0}
validates :capacity, :numericality => {:only_integer => true, :greater_than => 0}
validates :i... | true |
75a271d22313194441481f3adf9e4d2d008df3c9 | Ruby | Bcdirito/algorithm_problems | /array_manipulation/first_unique_character/basic.rb | UTF-8 | 814 | 4.1875 | 4 | [] | no_license | # Runtime 348 ms, Memory Usage 14 MB
def first_uniq_char(s)
# declare a history object with default values of 0
# this gets rid of the need for an if/else statement in our iterator
history = Hash.new(0)
# split the input string into an array of characters
split = s.split("")
# for each elemen... | true |
2daaacde139f9a867e3337a2b27591dafaed3eae | Ruby | krzkaczor/7-languages-7-weeks | /1-ruby/2-day/2.rb | UTF-8 | 655 | 3.46875 | 3 | [] | no_license | class Tree
attr_accessor :children, :node_name
def initialize(name, children = [])
@children = children
@node_name = name
end
def visit_all(&block)
visit &block
children.each { |c| c.visit_all &block }
end
def visit
yield self
end
end
def from_object(object_shape)
return [] if ob... | true |
b3a28041472493252fec0ffaac8d87c0f6e2efb7 | Ruby | ochaochaocha3/aoj-ochaochaocha3 | /0066.rb | UTF-8 | 464 | 3.78125 | 4 | [] | no_license | # AOJ 0066 Tic Tac Toe
while line = gets
r1, r2, r3 = line[0..2], line[3..5], line[6..8]
c1 = line[0] + line[3] + line[6]
c2 = line[1] + line[4] + line[7]
c3 = line[2] + line[5] + line[8]
d1 = line[0] + line[4] + line[8]
d2 = line[2] + line[4] + line[6]
result = "d"
[r1, r2, r3, c1, c2, c3, d1, d2].ea... | true |
785a179586db268a4a6deb6b0c4b6a152716a3fa | Ruby | lnemsick-simp/pupmod-simp-simpkv | /spec/acceptance/suites/default/validate_file_entries.rb | UTF-8 | 4,955 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | require 'acceptance/helpers/utils'
include Acceptance::Helpers::Utils
# Validate file-plugin-managed keys on the local filesystem
#
# - Conforms to the API specified in 'a simpkv plugin test' shared_examples
# - Uses local filesystem commands, since the file plugin has to be on the
# same host as the file keystore
#... | true |
a015a4aac7166debc6f701b55de6df759f681094 | Ruby | davehardy632/ps-code-challenge | /app/models/street_cafe.rb | UTF-8 | 2,584 | 2.84375 | 3 | [] | no_license | class StreetCafe < ApplicationRecord
validates_presence_of :name,
:street_address,
:post_code,
:number_of_chairs
def self.with_post_code_prefix(prefix)
prefix = prefix + " "
where("post_code LIKE ?", "#{prefix}%")
end
def self.ca... | true |
ba7f44e87ab34a0938bc5a8a5435a3e0e068899b | Ruby | aetzion1/sweater-weather | /app/poros/image.rb | UTF-8 | 503 | 2.78125 | 3 | [
"MIT"
] | permissive | class Image
attr_reader :id, :location, :image_url, :credits
def initialize(location, image, credits)
@id = nil
@location = location
@image_url = image[:urls][:raw]
@credits = format_credits(image[:user], credits)
end
def format_credits(user_info, credit_info)
{
author: user_info[:na... | true |
25e45099fdc7914d83f15bdfc66ec7de1815c0b4 | Ruby | revilo1882/bank_tech_test | /spec/account_spec.rb | UTF-8 | 816 | 2.953125 | 3 | [] | no_license | require 'account'
describe Account do
let(:statement) { double :statement }
let(:account) { Account.new(statement) }
describe '#initialize' do
it 'has a total of zero' do
expect(account.total).to eq(0)
end
end
describe '#credit' do
it 'adds the amount to the total' do
allow(stateme... | true |
25c812c90e1f447f2e6153f9d6855bd2bd1a8d0f | Ruby | hbcasper/CursoRuby | /condicionales_ciclos.rb | UTF-8 | 209 | 3.109375 | 3 | [] | no_license | frutas = ['manzana','pera','albaricoque']
frutas.each do |fruta|
#if fruta.start_with?('a')
# puts "#{fruta} empieza con la letra a"
if fruta.length>5
puts "#{fruta} tiene mas de 5 letras"
end
end | true |
522aa0da33d6fb3d83537435986ec6bef447ab04 | Ruby | ambervill/practice | /alias_method_chain/aliasing.rb | UTF-8 | 1,401 | 3.09375 | 3 | [] | no_license | module RubyLearning
module Aliasing
#
# 1. Strip out the final exclamation mark or question mark or equal mark
# from the name of the method, to put it at the end of the new aliases.
#
# 2. If block given, it can pass the aliased method name and punctuation
# to the block.
... | true |
d13590766e2ea8ec4cbbfac74a389a885253003f | Ruby | suzukieita/AOJ_algorithms_and_data_structures | /chap13/1_12_A.rb | UTF-8 | 961 | 3.203125 | 3 | [] | no_license | module Color
WHITE = 0
GRAY = 1
BLACK = 2
end
def prim()
d = Array.new($n, Float::INFINITY)
color = Array.new($n, Color::WHITE)
p = Array.new($n, -1)
d[0] = 0
while true
mincost = Float::INFINITY
u = nil
$n.times do |i|
if color[i] != Color::BLACK && d[i] < mincost
mincost... | true |
688fd84ba4126d29a05321bfce19214965ce20a3 | Ruby | aconstandinou/ls-exercises | /101_109_small_problems/easy_7/multiply_lists.rb | UTF-8 | 234 | 3.640625 | 4 | [] | no_license | def multiply_list(array_1, array_2)
product_array = []
array_1.each_with_index do |value, idx|
product_array << value * array_2[idx]
end
product_array
end
# Test Case
multiply_list([3, 5, 7], [9, 10, 11]) == [27, 50, 77]
| true |
0ae3130c1a7508b9fbd8e35400b33b917e6de8df | Ruby | chilbert/collections_practice_vol_2-online-web-prework | /collections_practice.rb | UTF-8 | 940 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def begins_with_r(array)
array.all? do |words|
words.start_with?("r")
end
end
def contain_a(array)
array.select do |words|
words.include?("a")
end
end
def first_wa(array)
array.find do |word|
word[0..1] == "wa"
end
end
def remove_non_strings(array)
array.grep(String)
end
def count_elements(ar... | true |
fc40480cb8e03b0c6f04bffe7967956833ed66c4 | Ruby | TheGrayWolf/Ruby_Exercises_and_Programs | /Escape_Characters.rb | UTF-8 | 687 | 3.75 | 4 | [] | no_license |
# Special bits of sintax that allow us to manipulate Strings
#For example: "" and '' you can use thse to put "" or '' in a String
# EXAMPLE:
puts "i said 'Goodbye' to fats";
puts 'I said "Goodbye" to fats';
puts
# To use same Quotes we need to tell ruby to escape these by putting a backslash \ before the quotes
... | true |
70fb0ac7c3a039842c75f89c89f3553fc9f5dc0d | Ruby | kylebragger/pfr-unit2-final | /app/models/shout.rb | UTF-8 | 481 | 2.53125 | 3 | [] | no_license | class Shout < ActiveRecord::Base
attr_accessible :content, :user, :tag_string
attr_accessor :tag_string
validates :content, presence: true, length: { maximum: 140 }
belongs_to :user
has_and_belongs_to_many :tags
before_save :process_tags
protected
def process_tags
tags = self.tag_s... | true |
64848d9475a323a021c4a3a5a3be2138c6ce6a27 | Ruby | kanaharuna/rspec_app | /spec/test_spec.rb | UTF-8 | 326 | 2.671875 | 3 | [] | no_license | describe '四則演算' do
context '足し算' do
it '1+1は2になる' do
expect(1 + 1).to eq 2
end
end
context '足し算' do
it '1+1は2になる' do
expect(1 + 1).to eq 3
end
end
context '引き算' do
it '3-2は1になる' do
expect(3 - 2).to eq 1
end
end
end | true |
9efdeec779de096fca7afdda26f65364e335dce5 | Ruby | dougdroper/anagram_finder | /spec/models/anagram_finder_spec.rb | UTF-8 | 666 | 2.65625 | 3 | [] | no_license | require_relative "../../app/models/anagram_search.rb"
describe "AnagramSearch" do
before do
@words = "begin\nbeing\nbeginning"
File.stub(:read => @words)
end
it "returns the anagrams of a word being searched for" do
AnagramSearch.new('dictionary.txt').find_annagrams("being").should == ["begin", "bei... | true |
019e229cccd6076a85c5515f72fe7c5b21ac1631 | Ruby | collabnix/dockerlabs | /vendor/bundle/ruby/2.6.0/gems/minitest-5.15.0/lib/minitest/spec.rb | UTF-8 | 9,228 | 2.671875 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | require "minitest/test"
class Module # :nodoc:
def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
block = dont_flip == :block
dont_flip = false if block
target_obj = block ? '_{obj.method}' : '_(obj)'
# warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
self.class_eval <<-EOM, ... | true |
66f614b60f3aef1c60300d62c63ba90fc3bb8047 | Ruby | gusmattos1/crowdfunder | /app/models/user.rb | UTF-8 | 607 | 2.515625 | 3 | [] | no_license | class User < ActiveRecord::Base
has_secure_password
has_many :projects
has_many :pledges
validates :password, length: { minimum: 8 }, on: :create
validates :password, confirmation: true, on: :create
validates :password_confirmation, presence: true, on: :create
validates :email, uniqueness: true
def t... | true |
ba18b5a25faf01d0dfcbec91c14187bc13669822 | Ruby | ericproulx/pluck_to_hash | /lib/pluck_to_hash/pluck_to_concern.rb | UTF-8 | 1,630 | 2.75 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'active_support/concern'
require 'active_support/hash_with_indifferent_access'
module PluckToConcern
extend ActiveSupport::Concern
module ClassMethods
def pluck_to_hash(*keys)
block_given = block_given?
hash_type = keys[-1].is_a?(Hash) ? keys.pop.fetch(:hash_... | true |
60d6b5c96ae2efbf6b033c605fe04627c908e6fd | Ruby | andrewhamon/thread_weaver_rb | /examples/thread_unsafe_run_at_most_once.rb | UTF-8 | 536 | 3.515625 | 4 | [
"MIT"
] | permissive | # This is a naively written routine whose intended purpose is to run the provided block at most
# once. In a single-threaded application this should work just fine, but if an instance of this
# class is shared among several threads who all try to invoke call on it, it will eventually fail at
# its intended purpose and ... | true |
a7d1e3d3832e2fcf1825d48c7f348749e2801273 | Ruby | sodatsu01/atcoder-problems | /abc/137/a.rb | UTF-8 | 60 | 2.921875 | 3 | [] | no_license | a, b = gets.split.map &:to_i
puts [a + b, a - b, a * b].max
| true |
291911622bdc449a2e563e8923820710d874ee00 | Ruby | whatalnk/cpsubmissions | /atcoder/ruby/arc019/arc019_2/1098700.rb | UTF-8 | 899 | 3.296875 | 3 | [] | no_license | # Contest ID: arc019
# Problem ID: arc019_2 ( https://atcoder.jp/contests/arc019/tasks/arc019_2 )
# Title: B. こだわりの名前
# Language: Ruby (1.9.3)
# Submitted: 2017-02-06 09:55:52 +0000 UTC ( https://atcoder.jp/contests/arc019/submissions/1098700 )
s = gets.chomp
n = s.length
if n == 1 then
puts 0
elsif n.even?
left ... | true |
c678d36e399781e74c7be304a99da1bd1e5f480b | Ruby | greenjoshua/RB101 | /small_problems/easy3/counting_chars.rb | UTF-8 | 239 | 4 | 4 | [] | no_license | # Please write word or multiple words: walk
# There are 4 characters in "walk".
puts "Please write word or multiple words: "
word = gets.chomp
characters = word.count(word, "^ ")
puts "There are #{characters} characters in \"#{word}\"." | true |
3a75f1b1490aa1426a2032a086d2548cf238897b | Ruby | christopheraue/ruby-evdev | /lib/evdev/converter.rb | UTF-8 | 919 | 2.609375 | 3 | [
"MIT"
] | permissive | class Evdev
module Converter; end
class << Converter
def code_to_type(code)
:"EV_#{code.to_s.split('_').first}"
end
def property_to_int(property)
LinuxInput.const_get(:"INPUT_PROP_#{property.upcase}")
end
def type_to_int(type)
LinuxInput.const_get(type.upcase)
end
de... | true |
08899a363f3e5ec797900193620d94da22be8e17 | Ruby | cielavenir/procon | /atcoder/arc/tyama_atcoderARC052B.rb | UTF-8 | 290 | 2.796875 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
calc=->r,h0,h{h<0 ? 0 : Math::PI/3*h*(r*h/h0)**2}
N,Q=gets.split.map &:to_i
A=N.times.map{gets.split.map &:to_f}
Q.times{
a,b=gets.split.map &:to_f
s=0
A.each{|x,r,h|
h0=x+h-[a,x].max
r=r*h0/h
s+=calc[r,h0,h0]-calc[r,h0,x+h-[b,x+h].min] if !(x+h<=a||b<=x)
}
p s
} | true |
d2460fbb159585787656564385ef54dbc0b845ca | Ruby | mgsnova/crisp | /spec/crisp/core_spec.rb | UTF-8 | 7,129 | 3.109375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe "the core language features" do
include Crisp::SpecHelper
it "should print results" do
evaluate("(println (+ 1 1))")
end
it "should bind values to symbols" do
evaluate("(def bla 3)")
end
it "should not allow to bind symbols twice" do
lambda do
evaluate("(... | true |
5e5497364063877103d43b8a38252c434c5fce89 | Ruby | claytonflesher/tales_of_bardorba | /lib/tales_of_bardorba/enemy.rb | UTF-8 | 530 | 2.65625 | 3 | [] | no_license | require_relative "character"
module TalesOfBardorba
class Enemy < Character
def initialize(name, hp, hit, defense, money)
super(name)
@hpmax = hp
@default_hit = hit
@default_defense = defense
@money = money
@hp = @hpmax
@hit ... | true |
f0cf92c533d7733cccc63e8ca9f6f9238c62cdd4 | Ruby | rystraum/property-1 | /lib/form_helpers.rb | UTF-8 | 363 | 2.59375 | 3 | [] | no_license | module FormHelpers
# From ActionPack
def check_box_checked?(value, checked_value = "1")
case value
when TrueClass, FalseClass
value
when NilClass
false
when Integer
value != 0
when String
value == checked_value
when Array
value.include?(checked_value)
els... | true |
6aa368573077f394ec052cd9141fbc4969b3815d | Ruby | sbrauer/traversa | /spec/traversa_spec.rb | UTF-8 | 6,249 | 2.625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Traversa do
it 'has a version number' do
expect(Traversa::VERSION).not_to be nil
end
before do
@root = SampleResourceWithChildren.new('', nil)
@branch = SampleResourceWithChildren.new('branch', @root)
@root.children = { 'branch' => @branch }
@leaf = SampleResou... | true |
5f1c15a8230754ee219edd01bee49f3d5eb95216 | Ruby | houtmanj/puppetlabs-stdlib | /lib/puppet/parser/functions/filter_hash_of_hash.rb | UTF-8 | 1,860 | 3.28125 | 3 | [
"Apache-2.0"
] | permissive | #
# filter_hash.rb
#
module Puppet::Parser::Functions
newfunction(:filter_hash_of_hash, :type => :rvalue, :doc => <<-EOS
This function filters an hash of hashes.
The first argument is the hash of hashes that is filtered.
The second argument is an hash and servers as the criteria.
The criteria hash is matched on the... | true |
52f110a0897836ecbe0e42cbbb468c40ab270c72 | Ruby | brooksRoley/CodeEvalChallenges | /word_count.rb | UTF-8 | 1,088 | 4.15625 | 4 | [] | no_license | # read a file line by line
# parse the words - []
# create a word_consistency hash for the count.
# output number of letters and each word at that spot.
def parse_to_array(line_as_string)
as_array = line_as_string.split(" ")
end
def create_consistency_hash(array_of_words)
consistency = {}
keys = []
# Create Al... | true |
814f3b8b76d61eab135a33f010edadce2e2760ae | Ruby | hoodielive/ruby | /old/classes/initialize.rb | UTF-8 | 559 | 4.0625 | 4 | [] | no_license | #!/usr/bin/env ruby
# initialize methods
class Animal
attr_accessor :name
attr_writer :color
attr_reader :legs, :arms
def initialize(noise, legs=4, arms=0)
@noise = noise
@legs = legs
@arms = arms
puts "A new animal has been instantiated (created an instance of it)"
... | true |
94af9100d69aa3037b97b7bfd6e354c617877e2d | Ruby | happyhappyhappyhappy/rubycode | /atcoderruby/begineersSelection/chap3/PASTFILES/ABC053B_1.rb | UTF-8 | 370 | 3.25 | 3 | [] | no_license | # Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Ruby 1st Try
si = gets.chomp.split('')
lengthm = si.size-1
apos = 0
zpos = si.size-1
0.step(lengthm,+1){|j|
if si[j] == 'A'
apos = j
break
end
}
lengthm.step(0,-1){|j|
if si[j] == 'Z'
zpos = j
break
end
}
# p ... | true |
03a536a2964ffff8c4909dc375d00ab90aa6f3e4 | Ruby | lightcn/ruby_demo | /hello_world3.rb | UTF-8 | 106 | 3.15625 | 3 | [] | no_license | class HelloWorld
def self.hello(name)
print name, " said Hello"
end
end
HelloWorld.hello("John")
| true |
738404465bb67e85b7978a742e9e082a714ff655 | Ruby | dylan-okeefe/do-i-neeed-my-umbrella | /app/models/location_data_model.rb | UTF-8 | 680 | 2.890625 | 3 | [] | no_license | class LocationData
attr_reader :city, :state, :country, :woeid, :location_count
attr_accessor :example
def initialize(data)
@parsed_html = data
end
def grab_values(counter)
@location_count = 0
if !@parsed_html.css('tr.woeid_row')[counter].nil?
@location_array = []
@city = @parsed_h... | true |
41c43af730fefc8305bb7c54dca7eb2d6b79ea53 | Ruby | torresga/launch-school-code | /lessons/130_lessons/lesson_1/todos_with_each.rb | UTF-8 | 2,073 | 4.03125 | 4 | [] | no_license | class Todo
DONE_MARKER = 'X'
UNDONE_MARKER = ' '
attr_accessor :title, :description, :done
def initialize(title, description= '')
@title = title
@description = description
@done = false
end
def done!
self.done = true
end
def done?
done
end
def undone!
self.done = false
... | true |
8a2c6850f29af02e363a1c3e9bddc845ffb410e1 | Ruby | princelab/xlink_PMF | /lib/tools/fft_R.rb | UTF-8 | 1,340 | 3.28125 | 3 | [
"MIT"
] | permissive | require 'rserve/simpler'
def arrays_to_complex_array(real, img)
raise StandardError unless real.size == img.size
real.each_with_index.map {|n, i| Complex(n, img[i]) }
end
def complex_array_to_arrays(complex_arr)
img = []
real = complex_arr.map {|n| img.push n.imag; n.real}
[real, img]
end
class FFT
def ini... | true |
cdcbb75964c7e0690d0764e975d4303cf58c893a | Ruby | mattscilipoti/ruproxr | /lib/proxr.rb | UTF-8 | 8,234 | 3.265625 | 3 | [] | no_license | require 'rubygems'
require 'serialport'
require 'timeout'
#Ruby wrapper for ProXR library.
#Used by the NCD ProXR Controllers (http://www.controlanything.com/Relay/SRCH).
class ProXR < SerialPort
COMMAND_MODE = 254
READ_VOLTAGE_8_BITS = 150
RELAY_OFF = 100
RELAY_ON = 108
RELAY_STATUS = 116
REPORTIN... | true |
6c2d23775bd78f02f1cea7954eea0bbe3ee6a70b | Ruby | cgillot/golf_switch | /lib/golf_switch/course_avail_request.rb | UTF-8 | 1,292 | 2.59375 | 3 | [
"MIT"
] | permissive | # avail_course = GolfSwitch::CourseAvailRequest.new
# avail_course.course_avails << GolfSwitch::CourseAvail.new(options)
# avail_course.course_avails << GolfSwitch::CourseAvail.new(options)
# avail_course.commit
module GolfSwitch
class CourseAvailRequest < GolfSwitch::Request
attr_accessor :course_avails,:api... | true |
f445c2672ad083cc9145da417f3cac14a309bdc0 | Ruby | alananobrega/rails-tdd | /exemplo_rspec_tdd/spec/matchers/comparacao_spec.rb | UTF-8 | 669 | 3.46875 | 3 | [] | no_license | #matchers
#matchers de igualdade
#equal / be (funciona no ruby)
#eql / eq
describe 'Matchers de Comparação' do
it '#equal - Testa se eh o mesmo objeto' do
x = "ruby"
y = "ruby"
expect(x).not_to equal(y)
expect(x).to equal(x)
end
it '#be - Testa se eh o mesmo obje... | true |
9de447ee88c32ab2095b0533764ce1940f21305d | Ruby | grzegorzblaszczyk/degiro | /lib/degiro_client/create_order.rb | UTF-8 | 2,151 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'json'
module DeGiro
class CreateOrder
BUY_SELL = { buy: "BUY", sell: "SELL" }.freeze
ORDER_TYPES = { limited: 0, stop_limited: 1, market_order: 2, stop_loss: 3 }.freeze
TIME_TYPES = { day: 1, permanent: 3 }.freeze
def initialize(connection)
@connection = connection
end
de... | true |
9de8faa7a0f47bb8ce7547da8156147b89d897f0 | Ruby | balvig/hub_link | /lib/hub_link/stream.rb | UTF-8 | 415 | 2.515625 | 3 | [
"MIT"
] | permissive | require "hub_link/batch"
module HubLink
class Stream
def initialize(repo, since: nil)
@repo = repo
@since = since&.to_date
end
def in_batches(&block)
page = 1
loop do
batch = Batch.new(repo: repo, since: since, page: page)
break if batch.empty?
yield batch... | true |
7a4842e93ad35cab43d953006a4fde2527eb475f | Ruby | toasterbob/review | /ruby/day6/chess/board.rb | UTF-8 | 917 | 3.5 | 4 | [] | no_license | require_relative 'pieces'
class Board
attr_accessor :rows
def initialize
@rows = make_starting_grid
end
def make_starting_grid
board = Array.new
2.times do
row = []
8.times do
row << Piece.new("white", [0,0], self, "\u2656")
end
board << row
end
4.times do... | true |
8e96e328c59f4a2087bdec7fd6febdb7dd1893f8 | Ruby | waihon/pragmaflix | /spec/models/user_spec.rb | UTF-8 | 7,586 | 2.84375 | 3 | [] | no_license | describe "A user" do
it "requires a name" do
# Arrange
user = User.new(name: "")
user.valid? # populates errors
# Assert
expect(user.errors[:name].any?).to eq(true)
end
it "requires an email" do
user = User.new(email: "")
user.valid?
expect(user.errors[:email].any?).to eq(true... | true |
85be659ea400864dbd39b42135f8c82e84c92b2e | Ruby | mmcderm8/average_grades | /code.rb | UTF-8 | 1,007 | 4.25 | 4 | [] | no_license | def average(grade_list)
sum = 0
grade_list.each do |grade|
sum += grade
end
sum / grade_list.size.to_f
end
jane_grades = [98, 95, 88, 97, 74]
jane_average = average(jane_grades)
puts jane_average # => 90.4
sam_grades = [85, 93, 98, 88, 49]
sam_average = average(sam_grades)
puts sam_average
matt_grades ... | true |
d14209961a2027dbb2ea9b30eb8a1582e9278916 | Ruby | CocoJu/rbstudy | /src/screencasts/17_arrays/arrays.rb | UTF-8 | 152 | 3.890625 | 4 | [] | no_license | names = ["Bob", "James", "John"]
p names
puts names[0]
puts names[1]
puts names[2]
puts names.class
names.pop
p names
names.shift
p names | true |
97640208066500ce317089e7e05f27deae931b93 | Ruby | violake/order_invoice | /lib/product.rb | UTF-8 | 1,413 | 3.09375 | 3 | [] | no_license | # frozen_string_literal: true
require 'order_error'
require 'products'
require 'pack'
require 'optimal_packer'
class Product
attr_reader :name, :quantity, :packs
def initialize(name, quantity)
product_spec = Products.find_by_name(name)
raise OrderError.new(OrderError::PARAMETER_INVALID, 'no such product'... | true |
e439375b1f6140fc5a9b455588485c8ffc4d5b8e | Ruby | OlgaSe/Jump-start-ADA | /walkaton.rb | UTF-8 | 1,450 | 4.0625 | 4 | [] | no_license | puts "Welcome to our Walk-A-Thon Tracker. Let's raise some money!"
puts "Enter the earning goal for our event: "
goal = gets.chomp.to_i # store user goal input to variable
puts "Enter the amount earned per lap (per person):"
lap = gets.chomp.to_i # store user input about earned per lap
puts "Please enter the number o... | true |
c10b84788840ba18836409f599828a57e3df0942 | Ruby | piotrb/config_volumizer | /lib/config_volumizer/generator.rb | UTF-8 | 1,791 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'ostruct'
module ConfigVolumizer
# Converts a {Hash} into a flattened {Hash} as a template for volumizing your configs
module Generator
class << self
# Generates a flattened config out of a data hash
#
# See Readme for an example
#
# @param [Hash] data
# @return [Ha... | true |
38765607097b461b2417a7bca4430c88c073e6b5 | Ruby | autonomous/Code-Coffee-Poker | /lib/player.rb | UTF-8 | 121 | 3.125 | 3 | [] | no_license | class Player
attr_reader :cards
def <<(cards)
@cards = cards
end
def discard
[@cards.pop]
end
end | true |
96667cd59856889a9fb37ae97c1f9b04a9f1952e | Ruby | Tomohiro-Kawakami-techcamp/RubySilver | /silver102.rb | UTF-8 | 415 | 3.390625 | 3 | [] | no_license | # trメソッドとtr_sメソッド
a = 'aabbccddeeffgg'
p a.tr('a-c', 'A-C')
p a.tr_s('a-c', 'A-C')
# deleteメソッド
a = 'aabbccddeeffgg'
p a
p a.delete('a-f', 'd-g')
# squeezeメソッド
a = 'aabbccddeeffgg'
p a.squeeze('a-e')
# replaceメソッド
a = 'abc'
p a
p a.replace('xyz')
puts a
# 文字列の連結
a = 'abc'
p a
p a.object_id
p a << 'def'
p a.object_i... | true |
d358540ca017deadad7d9b5b9cf3af3cabc3e787 | Ruby | timotheeguerin/uniiv | /app/models/user/invite.rb | UTF-8 | 667 | 2.640625 | 3 | [] | no_license | # User invites
class User::Invite < ActiveRecord::Base
validates_presence_of :message, :amount, :key, :used, :category
validate do
errors.add(:used, 'All invite have been used with this key!') if used > amount
end
before_validation :update_key, on: :create
def update_key
self.key = SecureRandom.he... | true |
be91f1551333387da23a58d1e0bc232752881529 | Ruby | Olidem/rails-longest-word-game | /app/controllers/games_controller.rb | UTF-8 | 879 | 3.109375 | 3 | [] | no_license | require 'open-uri'
require 'json'
class GamesController < ApplicationController
def new
alphabet = ("A".."Z").to_a
@letters = 9.times.map { alphabet.sample }.join(" ")
end
def score
@result = 'Well done!'
trial = params[:trial]
letters = params[:letters].gsub!(/\s/, '')
if !trial.upcase.... | true |
86b611b2332e8a9ab515d906b142f003b09559f7 | Ruby | TuranKavak/aA-Foundations-Projects | /Turan_Kavak_procs_project/lib/part_1.rb | UTF-8 | 1,075 | 3.703125 | 4 | [] | no_license | def my_map(enumerable, &block)
result = []
enumerable.each { |element| result << block.call(element) }
result
end
def my_select(enumerable, &block)
result = []
enumerable.each do |element|
if block.call(element) == true
result << element
end
end
result
end
def my_count(enumerable, &bloc... | true |
325ab5155db4366da0068468e570eaa752506986 | Ruby | oh2gxn/advent_of_code | /2019/spec/reaction_spec.rb | UTF-8 | 7,020 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../stoichiometry'
RSpec.describe Reaction do
let :required { described_class.solve(output, reactions) }
context 'with a really simple nanofactory' do
let :reactions do
{ 'A' => described_class.new('10 ORE => 10 A'),
'FUEL' => described_class.new('... | true |
560ad14a11824d9f29bd05fb5be2653e07d2576d | Ruby | keiko-kamataki/Attendance-Tutorial | /app/helpers/application_helper.rb | UTF-8 | 548 | 2.53125 | 3 | [] | no_license | module ApplicationHelper
# ページごとにタイトルを返す
def full_title(page_name = "") # メソッドと引数の定義
base_title = "AttendanceApp" # 基本となるアプリケーション
if page_name.empty? # 引数を受け取っているか判断
base_title # 引数 page_titleが空文字の場合は、base_titleのみ返す
else # 引数page_titleが空文字ではない場合
page_nam... | true |
94a165b3b3b4425e884f72363813b3079213425f | Ruby | thescouser89/snippets | /heading.rb | UTF-8 | 2,346 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'tempfile'
require 'fileutils'
# count the number of hashes
def hash_number(line)
count = 0
line.each_char do |char|
break if char != "#"
count += 1
end
# cases when text starts with #haha instead of # haha
if count != 0
if line[count] == ' '
count
else
0
end
else
... | true |
d5673eabb4d57bb7cdeb4d81ef4cf9872856a77a | Ruby | bradleypmartin/RubyDevTutorial | /sec13_grep/grepEx.rb | UTF-8 | 224 | 2.671875 | 3 | [] | no_license | arr = ['hey.rb', 'there.rb', 'index.html']
# Two different ways to filter results: grep is simpler!
# grep can be used in place of select and map.
p arr.select{|x| x =~ /\.rb/}.map{|x| x[0..-4]}
p arr.grep(/(.*)\.rb/){$1} | true |
f92c91902c1581ddbac333b5028dc5c3a6e61e72 | Ruby | stucaldor43/xvault | /db/region.rb | UTF-8 | 744 | 2.859375 | 3 | [] | no_license | require 'pg'
require_relative 'country_name_retriever'
class RegionTablePreparer
attr_reader :conn
def initialize
@conn = PG::Connection.open(
dbname: ENV['DATABASE_NAME'],
host: ENV['POSTGRESQL_HOST'] || ENV['IP'],
user: ENV['POSTGRESQL_USER'],
password... | true |
e05459726fa82628edae2949faf829cb675063ed | Ruby | sierraskyewallace/collections_practice-online-web-sp-000 | /collections_practice.rb | UTF-8 | 651 | 3.75 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
array.sort
end
def sort_array_desc(array)
array.sort {|x, y| y <=> x}
end
def sort_array_char_count(array)
array.sort {|a, b| a.size <=> b.size}
end
def swap_elements(array)
array[1], array[2] = array[2], array[1]
array
end
def reverse_array(array)
array.reverse
end
def kesh... | true |
103a4d7b6e00a651adc4aa25186fbe20e37eb553 | Ruby | faryar48/practice_bradfield | /09-07/simplifypath.rb | UTF-8 | 2,526 | 3.71875 | 4 | [] | no_license | # Given an absolute path for a file (Unix-style), simplify it.
# For example,
# path = "/home/", => "/home"
# path = "/a/./b/../../c/", => "/c"
# click to show corner cases.
# Corner Cases:
# Did you consider the case where path = "/../"?
# In this case, you should return "/".
# Another corner case is the path might ... | true |
46896faa077bcd026461d37b3516286658015888 | Ruby | nkrot/rufsl | /lesson.28/groups_numbers/group_numbers_stub | UTF-8 | 347 | 3.78125 | 4 | [] | no_license | #!/usr/bin/env ruby
numbers = [1, 3,4,5, 7, 9, 11,12,13,14]
grp_numbers = [[1], [3,4,5], [7], [9], [11,12,13,14]]
def group_numbers nums
grp = []
groups = [grp]
# TODO: add your code here
groups
end
puts "Initial: #{numbers.inspect}"
grouped = group_numbers(numbers)
puts "Grouped: #{grouped.inspect}"
p... | true |
c64a763493cb6046ddf68af1f9d126f1b05f3c64 | Ruby | tullio/dydx | /spec/lib/helper_spec.rb | UTF-8 | 2,707 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Helper do
include Helper
context '#is_n?' do
it { expect(0.is_0?).to be_true }
it { expect(_(0).is_0?).to be_true }
it { expect(inverse(0, :+).is_0?).to be_true }
it { expect(1.is_1?).to be_true }
it { expect(_(1).is_1?).to be_true }
it { expect(inverse(1, :*)... | true |
f76f2695f24731229541188b76a3a1280c8c3a0d | Ruby | Martje55555/Hangman | /lib/hangperson_game.rb | UTF-8 | 1,341 | 3.46875 | 3 | [] | no_license | class HangpersonGame
def initialize(word)
@word = word
@wrong_guesses = ""
@guesses = ""
end
def word()
@word
end
def wrong_guesses()
@wrong_guesses
end
def wrong_guesses_length()
@wrong_guesses.length
end
def guesses()
@guesses
end
def guess(lette... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.