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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ede8bac0c8e4919baa34d82a6cd1270f7c59cdf8 | Ruby | tmtocb/abecadlo | /app/api/v1/players/services/list.rb | UTF-8 | 709 | 2.71875 | 3 | [] | no_license | module V1
module Players
module Services
class List
def initialize(all_players)
@all_players = all_players
end
def call
@all_players.map do |player|
player_structure(player)
end
end
private
def player_structure(play... | true |
163d9abb350f521ef8852a16d6682b05b332bd4f | Ruby | pcarolan/drought-monitor-api | /app/helpers/geojson_helper.rb | UTF-8 | 845 | 2.890625 | 3 | [] | no_license | module GeojsonHelper
# this method takes in a RGeo geometry object and returns a GeoJSON object
def to_geojson(geometry_collection)
geojson_object = {}
geojson_object["type"] = "FeatureCollection"
geojson_object["features"] = []
geometry_collection.each_with_index do |record, index|
fea... | true |
2b7358810bc56f0bc0906144605025752a8e0ff6 | Ruby | makevoid/dokku_config_converter | /lib/config_converter.rb | UTF-8 | 389 | 2.71875 | 3 | [] | no_license | path = File.expand_path "../../", __FILE__
CONFIGS = "#{path}/configs.txt"
raise "Config file not found" unless File.exist? CONFIGS
configs = File.read CONFIGS
matches = []
configs.each_line do |line|
match = line.match /^(\w+):\s+(.+)$/
name, value = match[1], match[2]
matches << "#{name}=#{value}"
end
puts ... | true |
0e65de311c1d8674d21ef105a1442cab26b5916e | Ruby | luizmoitinho/ruby-examples | /OO/computer.rb | UTF-8 | 200 | 3.21875 | 3 | [] | no_license | class Computer
def turn_on
'turn on the computer'
end
def shutdown
'shutdown the computer'
end
end
my_computer = Computer.new
puts my_computer.turn_on
puts my_computer.shutdown | true |
44910f5c150dadb9feab1e56d1d173385d1467c7 | Ruby | LiamKeene/ikumentary-blog | /spec/helpers/article_helper_spec.rb | UTF-8 | 1,418 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe ArticleHelper do
let(:pub_article) { create(:article, published_at: 'Sat, 25 Jan 2014 11:02:40 UTC +00:00') }
let(:draft_article) { create(:article, :draft) }
describe 'format_published_date' do
let(:pub_date) { format_published_date(pub_article.published_at) }
let(:pub... | true |
8e8c96e0b4623881bb27835c63acc5865541385f | Ruby | AEminium/plaid-lang | /tartan/lib/parser/ast/state_def.rb | UTF-8 | 903 | 3.0625 | 3 | [] | no_license | module Parser
module AST
class StateDef
attr_accessor :linum, :id, :literal, :and_states, :children, :parent
def initialize(linum, id, literal=nil, and_states=[], parent = nil)
@linum = linum
@id = id
@literal = literal
@and_states = and_states
@parent = parent... | true |
44c5ad818b55e20e27ec96a4adc83deb359debe5 | Ruby | gabeodess/Punchfork | /test/punchfork_test.rb | UTF-8 | 1,143 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class PunchforkTest < ActiveSupport::TestCase
def setup
end
test "should use http by default" do
Punchfork.setup { |config| config.protocol = 'http' }
assert_equal 'http', URI.parse(Punchfork.search_url(:tomatoes).to_s).scheme
end
test "should use https" do
Punchf... | true |
8255f464889d00ff3060d4a2d38ed5466dc090e3 | Ruby | lefant/whole_history_rating | /lib/whole_history_rating/player.rb | UTF-8 | 6,230 | 3 | 3 | [
"MIT"
] | permissive | require 'matrix'
module WholeHistoryRating
class Player
attr_accessor :name, :anchor_gamma, :days, :w2, :debug, :id
def initialize(name, config)
@name = name
@debug = config[:debug]
@w2 = (Math.sqrt(config[:w2])*Math.log(10)/400)**2 # Convert from elo^2 to r^2
@days = []
end
... | true |
860c029b0a97cd154b365d2493b88e835391173a | Ruby | nalexiou/prep_ruby_challenges | /uniques.rb | UTF-8 | 195 | 3.40625 | 3 | [] | no_license | def uniques(arg)
result = []
arg.each do |x|
if !result.include?(x) then
result.push(x)
end
end
return result
end
p uniques([1,5,"frog", 2,1,3,"frog"])
p uniques([1,4,2,4,33,2,44,43]) | true |
6105e92410e0af68b716eee62c2cca81eb1a9859 | Ruby | tonykung06/ruby-example | /method_visibility.rb | UTF-8 | 480 | 3 | 3 | [] | no_license | class Spaceship
def self.disable_engine
end
private_class_method :disable_engine
def launch
batten_hatches
end
def batten_hatches
puts "Batten the hatches!"
end
private :batten_hatches
end
class SpritelySpaceship < Spaceship
def initialize
batten_hatches
end
end
#private methods c... | true |
21ebdbd047cd330ff8d7fc51444d3f317998bf71 | Ruby | krismac/course_notes | /week_01/day_2/functions_lab/solution/ruby_functions_practice_solution.rb | UTF-8 | 1,449 | 4.1875 | 4 | [] | no_license | def return_10()
return 10
end
def add(first_number,second_number)
return first_number + second_number
end
def subtract(first_number,second_number)
return first_number - second_number
end
def multiply(first_number,second_number)
return first_number * second_number
end
def divide(first_number,second_number)
... | true |
db2f4d72ba91fd6ab6c52ace07ca7fffc2973571 | Ruby | seinosuke/sabina | /lib/sabina/utils.rb | UTF-8 | 207 | 2.640625 | 3 | [
"MIT"
] | permissive | module Sabina
module Utils
def box_muller(s = 1.0)
r_1 = rand
r_2 = rand
s * Math.sqrt(-2*Math.log(r_1)) * Math.cos(2*Math::PI*r_2)
end
module_function :box_muller
end
end
| true |
1d84f0ee7003f616e4b7c73e551639f479637c68 | Ruby | emico7/sep-assignments | /01-data-structures/02-stacks-and-queues/mystack/mystack.rb | UTF-8 | 285 | 3.359375 | 3 | [] | no_license | class MyStack
attr_accessor :stack
def initialize
self.stack = Array.new
# self.top = nil
end
def top
stack.last
end
def push(item)
stack << item
end
def pop
stack.delete_at(-1)
end
def empty?
stack.length == 0 ? true : false
end
end
| true |
d31906389ca43cef30a220dcc237cf1d134623f4 | Ruby | williamkennedy/OdinRubyBuildingBlocks | /CaeserCipher.rb | UTF-8 | 458 | 3.890625 | 4 | [] | no_license | def caesar_cipher(word, shiftNum)
smallLetters = ('A' .. 'Z').to_a #creating array of lowercase letters
bigLetters = ('a' .. 'z').to_a #creating array of uppercase letters
abcs = smallLetters += bigLetters #combined two arrays in to one
newWord = " " #made a blank word
word.each_char do |... | true |
0f31b9f44c3084b41749ba7680d1d1423dff2a73 | Ruby | bibbycodes/tic-tac-toe | /lib/board.rb | UTF-8 | 954 | 3.4375 | 3 | [] | no_license | # frozen_string_literal: true
class Board
attr_reader :layout
def initialize
@layout = {
'A' => { "1": ' ', "2": ' ', "3": ' ' },
'B' => { "1": ' ', "2": ' ', "3": ' ' },
'C' => { "1": ' ', "2": ' ', "3": ' ' }
}
end
def add(player, position)
piece = player.piece
if valida... | true |
1438afd3e150376a18e18432ac3b28b63fd12d02 | Ruby | syucream/ts_mruby | /examples/key/key.rb | UTF-8 | 5,326 | 2.640625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | #
# Process 'Key' header field value and set secondary cache key
#
class KeyProcessor
def initialize(host, port)
@redis = Redis.new host, port
req = ATS::Request.new
@url = "#{req.scheme}://#{req.hostname}#{req.uri}#{req.args}"
end
#
# Calculate and set secondary cache key
#
def process
ke... | true |
1f172a9a8fc58ae8b4382d6b8d0c8a41357ef185 | Ruby | mhickman84/redex | /spec/redex/document_type_spec.rb | UTF-8 | 2,951 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require File.expand_path('../spec_helper', File.dirname(__FILE__))
module Redex
describe DocumentType do
include RedexHelper
before(:each) do
@letter_doc_type = Redex.define_doc_type :letter
@test_doc_type = DocumentType.new :test_doc do |d|
d.should be_a DocumentType
d.has_secti... | true |
e7c1336f966a21eb5fc6c95fd49ae99052b176a8 | Ruby | nettan20/third_base | /spec/date/ordinal_spec.rb | UTF-8 | 545 | 2.65625 | 3 | [
"MIT"
] | permissive | require(File.join(File.dirname(__FILE__), '..', 'date_spec_helper'))
describe "Date#ordinal" do
it "should be able to construct a Date object from an ordinal date" do
lambda { Date.ordinal(1900, 366) }.should raise_error(ArgumentError)
lambda { Date.ordinal(1900, 365) }.should_not raise_error(ArgumentError)... | true |
0b5bc138fe6448affaf9c25f44532b530a18bdec | Ruby | nbudin/rubycas-server | /lib/casserver/localization.rb | UTF-8 | 2,534 | 2.546875 | 3 | [
"MIT"
] | permissive | require "gettext"
require "gettext/cgi"
module CASServer
include GetText
bindtextdomain("rubycas-server", :path => File.join(File.dirname(File.expand_path(__FILE__)), "../../locale"))
def service(*a)
GetText.locale = determine_locale
#puts GetText.locale.inspect
super(*a)
end
def determine_loca... | true |
cb0ae7bf400456dc8c1e9700b1d3a21683f98939 | Ruby | harishraisinghani/two-player-game | /logic_method.rb | UTF-8 | 1,350 | 3.953125 | 4 | [] | no_license | #Method to generate game questions
def generate_question
@rand_arr = []
2.times do
@rand_arr << rand(1..20)
end
"#{@rand_arr[0]} + #{@rand_arr[1]}"
end
#Method to verify user answer
def verify_answer?(input)
@rand_arr[0] + @rand_arr[1] == input
end
#Method to score a point
def score(player)
@players... | true |
f9e60064317edd71e5a39b7b66d48e04883fa1cd | Ruby | rpremvaree12/codecademy-projects | /ruby/methods/formatter.rb | UTF-8 | 474 | 4.25 | 4 | [] | no_license | def formatter
puts "What's your first name?"
first_name = gets.chomp #.capitalize! returns nil if there are no changes
first_name.capitalize!
puts "What's your last name?"
last_name = gets.chomp
last_name.capitalize!
puts "What city do you live in?"
city = gets.chomp
city.capitalize!
puts "What ... | true |
3cbee611190d326e65a43e5fe13dc27518f70cf5 | Ruby | Carpk/record_listings | /lib/record_list/file_parser.rb | UTF-8 | 1,187 | 3.3125 | 3 | [] | no_license | require "csv"
class FileParser
def initialize(file_names)
@files_list = file_names
end
def load_listed
data_files.map { |file| read_file(file) }.flatten
end
def add_to_file(record)
open_file(data_files.last, 'a') {|f| f << record + "\n"}
end
private
def create_person(person_data)
P... | true |
e2e5b545a7287fccfe589e56faab16e61b9f1488 | Ruby | tremulaes/blackmetal-b-star | /background.rb | UTF-8 | 1,075 | 2.765625 | 3 | [] | no_license | class Background
def initialize(game, scrolling = true)
@game = game
load_map(scrolling)
@frame = 0
calc_images if scrolling
@y = -1080 * 2 - 480
@vel = 4
@scrolling = scrolling
end
def update
if @scrolling
reset_picture if switch_frame?(@y)
@y += @vel
end
e... | true |
463fdbc53b7830aa91ca389665768d8a3372df8d | Ruby | Solveug/Tutorial-Simdyanov | /chapter4/task6.rb | UTF-8 | 315 | 3.609375 | 4 | [] | no_license | a = {x: 3, y: 7}
b = {x: -1, y: 5}
#ac = xb - xa
#bc = yb - ya
#ab = sqrt((ac)**2 + (bc)**2)
#ab = sqrt((xb - xa)**2 + (yb - ya)**2)
#ab = Math::sqrt((-1 - 3)**2 + (5 - 7)**2)
ab = Math::sqrt((b[:x] - a[:x])**2 + (b[:y] - a[:y])**2)
puts "Расстояние между точками A и B равно: #{ab}"
| true |
0a24be6ceb24a601ae33d392dc205ef4e97f9039 | Ruby | danielpclark/PMMC | /v3/controller.rb | UTF-8 | 2,843 | 2.75 | 3 | [
"MIT"
] | permissive | $:.unshift "."
PLdirectory = "payloads/"
module ControllerPL
@sampleDB = {"user" => "KingOfWorld", "pass" => "IAmLegend", "email" => "BowToMe@MyDomain.gov", "firstname" => "Jean", "lastname" => "Jeffries"}
class << self
# Returns the sampleDB values.
attr_accessor :sampleDB
end
def requestor(modulePL,featu... | true |
1c21dd50b2483b3be76006a4b6d41708e59203a0 | Ruby | zerohun/praiseme | /test/models/comment_test.rb | UTF-8 | 625 | 2.53125 | 3 | [] | no_license | require 'test_helper'
class CommentTest < ActiveSupport::TestCase
test "is_destroyable_by? should return true for author as parameter" do
comment = comments(:one)
assert comment.is_destroyable_by?(users(:zerohun))
end
test "User can destroy comments written by someone else for compliment he receive... | true |
640f1700efaecd92a372919c974055a45dad39f4 | Ruby | fairchild/one-mirror | /src/cloud/common/Configuration.rb | UTF-8 | 3,694 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | # -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# no... | true |
5f55aedb07ae4ff431c399c703a73982da298670 | Ruby | ida0622/2-7 | /lesson6.rb | UTF-8 | 258 | 3.140625 | 3 | [] | no_license | total_price=100
if
total_price>100
puts "みかんを購入。所持金に余りあり"
elsif
total_price==100
puts "みかんを購入。所持金は0円"
else
total_price<100
puts "みかんを購入することができません"
end
| true |
89c86711973254687848f076845ea23315663305 | Ruby | ensallee/sql-crowdfunding-lab-nyc-web-042318 | /lib/sql_queries.rb | UTF-8 | 2,259 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your sql queries in this file in the appropriate method like the example below:
#
# def select_category_from_projects
# "SELECT category FROM projects;"
# end
# Make sure each ruby method returns a string containing a valid SQL statement.
# CREATE TABLE projects (
# id INTEGER PRIMARY KEY,
# title TEXT,
#... | true |
7cd554c745ec37555388bad8d100d29781be02a9 | Ruby | yovasx2/conekta | /app/models/card.rb | UTF-8 | 1,066 | 2.53125 | 3 | [
"MIT"
] | permissive | class Card < ApplicationRecord
validates :card_number, :expiration_month, :expiration_year, :secure_code, presence: true
validates :card_number, length: { is: 16 }
validates :expiration_month, :expiration_year, length: { maximum: 2 }
# TODO add a validator for credit card number, but bank is missing in params
... | true |
4e1976fd2a7f1bfb19173d96ff649d8e47898cba | Ruby | marcos-x86/AT04_API_test | /AbelBarrientos/Exam/logger.rb | UTF-8 | 245 | 2.671875 | 3 | [] | no_license | module Logger
def add_line value
file = File.open("execution.log", 'a')
file.write "%s\n" % value
file.close
end
def add_array array
file = File.open("execution.log", 'a')
file.write p array
file.close
end
end
| true |
21b2d55ee7bc72ecc0493b278ff73109866b4ab5 | Ruby | cmdjohnson/gridomatic | /app/helpers/gridomatic_helper.rb | UTF-8 | 6,096 | 2.640625 | 3 | [
"MIT"
] | permissive | # -*- encoding : utf-8 -*-
module GridomaticHelper
COLORS = %w( blue red green yellow cyan orange purple )
# Render multiple boxes.
# Takes as argument a single array of Hash
# For the Hash options, please see render_box.
#
# The boxes are wrapped in a div with class "textboxes".
# You can pass individua... | true |
3e01bc821e509d7c1817aec9da06dd8daddbdd6d | Ruby | jstoos/ruby-collaborating-objects-lab-v-000 | /lib/mp3_importer.rb | UTF-8 | 378 | 2.765625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class MP3Importer
attr_accessor :song
def initialize(file_path)
@file_path = file_path
end
def path
@file_path
end
def import
files.each{|filename| Song.new_by_filename(filename)}
end
def files
files = Dir.glob("#{@file_path}/*")
files.each do |long_name|
... | true |
d54f14ed7ff5147902e18624f52a200e04d84843 | Ruby | usuyama/variant_parser | /ruby/sam_parser.rb | UTF-8 | 4,073 | 2.90625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pattern-match'
class Variant
attr_accessor :type, :ref, :obs, :left, :right, :len
# init by giving a hash
def initialize(attributes={})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def self.from_cigar(c)
v = Variant.new({:len => c[0..-2].t... | true |
b08a0e9f1d21491a7abf064c0b8aef787ffed744 | Ruby | itggot-william-bruun/standard-biblioteket | /lib/split_char.rb | UTF-8 | 277 | 4.15625 | 4 | [] | no_license | #Public: Segments a string at specified intevalls and put these into a array.
#
#string - The string to turn into a array
#
#Examples
#
# split("1;2;3;4;5;", ";")
# # => ["1", "2", "3", "4", "5"]
#
#Returns a array of the string
def split(string, n)
string.split(n)
end | true |
b776501ea35055399edc1857f61b5ba68568218c | Ruby | celeste137/Itsa-me-Mario- | /exo_12.rb | UTF-8 | 140 | 3.328125 | 3 | [] | no_license | puts "Hello again visiteur ! Choisi un nombre..."
visitor_number = gets.chomp.to_i
i = 0
visitor_number.times do |i|
puts "#{i+1}"
end | true |
5cdc03aebc535b081d4828ec47d8b1554aeba540 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/e2c26fb28c3a439eb063f79e129289ca.rb | UTF-8 | 539 | 3.71875 | 4 | [] | no_license | class Phrase
attr_reader :phrase
def initialize(phrase)
@phrase = phrase
end
def word_count
occurrences = Occurrences.new
words.each { |word| occurrences << word }
occurrences.result
end
def words
phrase.split(/[^'\w]/).reject { |word| word == '' }
end
end
class Occurrences
attr_... | true |
8daf8546cc1d28611f7fa1414ed332dbda825e14 | Ruby | dmcouncil/resource-locker | /lock.rb | UTF-8 | 1,759 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'sinatra'
require 'sinatra/activerecord'
require './app/models/resource'
require './app/models/message'
# This is the Slack endpoint
post '/' do
return [400, ["Bad token"]] unless request['token'] == ENV['SLACK_REQUEST_TOKEN']
resource_name, duration = request['text'].split unless request['text'].blank?
... | true |
ae73dcdb54dfdf3da1848fe7574b1f05c75fc287 | Ruby | Murphydbuffalo/Learn_To_Program | /Ch10/old_shuffle.rb | UTF-8 | 968 | 3.96875 | 4 | [] | no_license | unsorted1 = make_list
sorted = []
unsorted2 = []
def shuffle_list unsorted1, sorted, unsorted2 #Must separate variables by commas. No parentheses needed.
if unsorted1.last.length <= unsorted1[rand(unsorted1.length)].length
sorted = sorted.push unsorted1.last
unsorted1.pop
shuf... | true |
20ace7fdfd5dae7d08e3c8b947399c8626f2a566 | Ruby | ben-harvey/Small-problems-Ruby | /oop/oo_basics4/3.rb | UTF-8 | 221 | 3.40625 | 3 | [] | no_license | class Person
attr_reader :phone_number
def initialize(number)
@phone_number = number
end
end
person1 = Person.new('898789')
puts person1.phone_number
person1.phone_number = '8989'
puts person1.phone_number
| true |
6fb42a93dd5ac88adf8165de70af0c27ab562b42 | Ruby | AJuliette/live-colonies | /app/models/payment.rb | UTF-8 | 2,129 | 3.171875 | 3 | [] | no_license | # frozen_string_literal: true
class Payment < ApplicationRecord
belongs_to :stay
# In order to get the price with a discount percentage applied on certain days of the month, I first use a method (l 31) to get the number of days in the month concerned by the discount. To do that, I check if the YearMonth of the da... | true |
24ecb2e32647b9de68fc350dae64929b19fd52c8 | Ruby | loyno-mathcs/workforwardnola | /awsemailer.rb | UTF-8 | 2,482 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'aws-sdk-ses' # v2: require 'aws-sdk'
require './emailer.rb'
require 'dotenv'
require 'mime'
module WorkForwardNola
# Class for sending out emails through AWS
class AwsEmailer < Emailer
Dotenv.load
def initialize(access, secret)
Aws.config.update(credentials: Aws::Credentials.new(access, sec... | true |
817251a2d9e6ea63bc3f55a2c9a4be07b4cb6bdc | Ruby | morenoh149/TheAlgorithmDesignManual | /projectEuler/21_amicable_numbers.rb | UTF-8 | 647 | 3.9375 | 4 | [] | no_license | require 'set'
def sum_of_divisors(n)
divisors = divisors(n)
divisors.inject{ |result, element| result + element }
end
def divisors(n)
result = [1]
ciel = Math.sqrt(n).to_i + 1
(2..ciel).each do |d|
if n%d == 0
result << d
result << n/d
end
end
result.sort
end
def find_amicable(n)
res... | true |
c9bf9a78bfbbe6492920c7e29520f5e8545b592b | Ruby | awijnen/ruby_exercises | /assignment10_hashketball_andrew.rb | UTF-8 | 7,328 | 3.359375 | 3 | [] | no_license | # Hashketball Nests
#
# Great news! You're going to an NBA game! The only catch is that you've been
# volunteered to keep stats at the game.
# Using Nested Hashes, define a game, with two teams, their players, and the players stats:
# The game has two teams.
#
# A team has:
# - A name
# - Two colors
#
# Each team shoul... | true |
8994f2bda32448030df10ab16d0f1d1146c5a180 | Ruby | mvanholstyn/harvested | /lib/harvest/line_item.rb | UTF-8 | 1,175 | 2.6875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Harvest
# The model that contains information about a client
#
# == Fields
# [+id+] (READONLY) the id of the client
# [+name+] (REQUIRED) the name of the client
# [+details+] the details of the client
# [+currency+] what type of currency is associated with the client
# [+currency_symbol+] what cu... | true |
fb3f18d29149b446cf996f94f9113e84fe4873a5 | Ruby | takenokoya/camp_weekday_task6 | /incentiveRanking.rb | UTF-8 | 2,942 | 3.703125 | 4 | [] | no_license | # 問題:
# VERTEXグループは勉強熱心なエンジニアに奨励金を出すために
# 各メンバーが学習に費やした金額を可視化しようとしています。
# メンバーそれぞれの学習費用を計算し
# 値が高い人から順に名前と金額を出力するプログラムを作成してください。
#
# 入力は、data00*.txt(* = 1~3)ファイルから与えられます。
# ・1 行目に、人数 N が文字列型の整数で与えられます。
# ・2 行目に、半角英文字で構成される文字列が N 個スペース区切りで与えられます。
# ・3 行目に、全メンバーが学習した回数 M が文字列型の整数で与えられます。
... | true |
690cf83159ee8d69411845936fb2110d510290f2 | Ruby | Rizzooo/school-domain-onl01-seng-pt-052620 | /lib/school.rb | UTF-8 | 424 | 3.640625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class School
attr_reader :name, :roster
def initialize(name)
@name = name
@roster = {}
end
def add_student(names, grades)
roster[grades] ||= []
roster[grades] << names
end
def grade(student_grades)
roster[student_grades]
end
def sort
sorted_list = {}
roster.each ... | true |
2b57c2021d772bfa0b338427f499ad1cabda2d49 | Ruby | james/Strong-Wind | /app/models/location.rb | UTF-8 | 484 | 2.609375 | 3 | [] | no_license | class Location < ActiveRecord::Base
validates_presence_of :lat, :lng
def self.new_from_results(results)
new(
:lat => results["latitude"],
:lng => results["longitude"],
:accuracy => results["accuracy"],
:found_at => "#{results["date"]} #{results["time"]}"
)
end
def duplicate_of... | true |
2b433838dfda2567a018dba2292fab8d6226edaf | Ruby | kvnkwon/payrollrails | /app/models/sale.rb | UTF-8 | 914 | 3.484375 | 3 | [] | no_license | require 'csv'
class Sale
@@sales_info = []
@@sales_person = {}
def initialize(sales = {})
@last_name = sales['last_name']
@amount = sales['gross_sale_value']
end
def self.read_info(file_path)
@@sales_info = []
CSV.foreach(file_path, headers: true) do |row|
sales = row.to_hash
... | true |
4ccefa9fd84701233f5af504d7226f03a41cce86 | Ruby | edhowland/vish | /lib/analysis/tree_utils.rb | UTF-8 | 2,879 | 3.09375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # tre_utils.rb - Module TreeUtils : like copy_tree
# TreeUtils - Used in optimizers within VishCompiler
module TreeUtils
include ListProc
##
def contains? tree, sym, result=false
if null?(tree)
result
elsif list?(car(tree)) && caar(tree) == sym
contains?(cdr(tree), sym, true)
else
contains?(c... | true |
697553ed62210e2dc910be3e6ed8fd7e730d0c69 | Ruby | josepwil/math_game | /game.rb | UTF-8 | 1,319 | 3.921875 | 4 | [] | no_license | class Game
attr_accessor :current_player
def initialize
@player_one = Player.new("Player 1")
@player_two = Player.new("Player 2")
@current_player = @player_one
puts "Welcome #{@player_one.name} and #{@player_two.name} to a new game!"
end
def play
while @player_one.lives > 0 && @player_... | true |
55df8204f597357a39ca36d644edeb5a9f6b4e02 | Ruby | kowaraj/Books | /books/SevenLanguagesInSevenWeeks/Ruby/d2_class_use_module.rb | UTF-8 | 235 | 2.6875 | 3 | [] | no_license | $LOAD_PATH << "."
require 'd2_module.rb'
class A
include ToFi
attr_accessor :name
def initialize(name)
@name = name
end
def method_get_name_of_someclass
'my name is = '+name+"\n"
end
end
A.new('vasya').to_f
| true |
b5019c1251bfba38e10e4301de5c42245aee94e5 | Ruby | CaDs/dynamometer | /miner.rb | UTF-8 | 2,613 | 2.671875 | 3 | [] | no_license | require "rubygems"
require "bundler/setup"
require 'sidekiq'
require 'redis'
require 'json'
require 'securerandom.rb'
# If your client is single-threaded, we just need a single connection in our Redis connection pool
Sidekiq.configure_client do |config|
config.redis = { :namespace => 'dynamometer', :size => 1, :url =... | true |
3f9d4c32d02055226063887685f314d001b342d2 | Ruby | wenlilearn/leetcode | /num_2_hex/main.rb | UTF-8 | 1,093 | 3.90625 | 4 | [] | no_license | =begin
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.
Note:
All letters in hexadecimal (a-f) must be in lowercase.
The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero cha... | true |
cb320db6c4c13d30eeb1b8a48c5c8b3cedcaa655 | Ruby | meredithkfwilliams/challenges | /korning/import.rb | UTF-8 | 3,517 | 3.25 | 3 | [] | no_license | require "pg"
require "csv"
require "date"
require "set"
system "psql korning < schema.sql"
############
# METHODS #
###########
#Database connection helper method
def db_connection
begin
connection = PG.connect(dbname: "korning")
yield(connection)
ensure
connection.close
end
end
#Methods to parse ... | true |
8a0a2d8a069107bb5d033fef64014c23567f0ef8 | Ruby | tintinmar/operators-001-prework-web | /lib/operations.rb | UTF-8 | 157 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def unsafe?(speed)
if speed<40 || speed > 60
return true
else return false
end
end
def not_safe?(speed)
speed>60 || speed<40 ? true : false
end
| true |
7d6a77d1f12e80e014b5dc85977009c68010704f | Ruby | robwold/compact | /test/contract_test.rb | UTF-8 | 2,991 | 2.75 | 3 | [
"MIT"
] | permissive | require_relative './test_helper'
require_relative './dumb_object'
require 'mocha/minitest'
class ContractTest < MiniTest::Test
def new_contract
@subject = Contract.new
end
def contract_with_spec
contract = new_contract
contract.add_invocation(example_invocation)
contract
end
def example_in... | true |
2ea8229db6c69d39cb3db418fdacb194b2fabf5a | Ruby | code-monkey-88/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 1,454 | 4.3125 | 4 | [] | no_license | #adding an interface:
#apply conditional logic to determine if user would like to encrypy or decrypt
#ask for user input
#somehow interpolate results to call appropriate method
puts "would you like to decrypt or encrypt a password?"
user_input=gets.chomp
if user_input=="decrypt"
puts "what would you like to dec... | true |
bf6690617ddf5890a416743a5c6245018edd6d49 | Ruby | qirun-chen/ruby-labs | /ruby-5/itunes.rb | UTF-8 | 1,837 | 3.109375 | 3 | [] | no_license | #!/usr/bin/ruby -w
# iTUNES
# Copyright Mark Keane, All Rights Reserved, 2014
#This is the top level
require 'csv'
require_relative 'actor'
require_relative 'album'
require_relative 'song'
require_relative 'reader'
require_relative 'utilities'
require_relative 'error'
songs_file = ARGV[0].nil? ? 'songs.csv' : ARGV[0]... | true |
a34bd519255f2388052ecb73128139dc93c7cfaa | Ruby | tinygrasshopper/basic_crawler | /spec/lib/link_queue_spec.rb | UTF-8 | 1,585 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
describe LinkQueue do
subject { LinkQueue.new(3, 3) }
context :enqueue do
it 'should add an item to the queue' do
link = Link.new('/', nil)
expect { subject.enqueue(link) }.to change { subject.count }.from(0).to(1)
end
it 'should not add a link if link depth is exceed... | true |
6f162d5212fe35150306717e3b3091cec851998d | Ruby | haraguchi12/paiza | /sanple80.rb | UTF-8 | 89 | 2.703125 | 3 | [] | no_license | N_1 =gets.chomp
N_2 =gets.chomp
N_3 =gets.chomp
puts N_1.to_s+"-"+N_2.to_s+"-"+N_3.to_s | true |
2ba5e88c5af9ffe150fe6220e3c2140ff68a7a8d | Ruby | juuh42dias/Hours | /spec/support/entry_stats_helper.rb | UTF-8 | 849 | 2.625 | 3 | [
"MIT"
] | permissive | def entry_with_hours_project(hours, project)
create(:hour, value: hours, project: project)
end
def entry_with_hours_user(hours, user)
create(:hour, value: hours, user: user)
end
def entry_with_hours(hours)
create(:hour, value: hours)
end
def entry_with_hours_tag(hours, tag)
create(:hour, value: hours).tags <... | true |
2bd19b3a607c0ac7f4d9bb6f629af6f5dd9623d6 | Ruby | captain91/fastlaneexpand | /testfile/trans.rb | UTF-8 | 2,042 | 2.875 | 3 | [] | no_license | #!/usr/bin/ruby
require 'fileutils'
# path = "fastlane/metadata/"
# tagL = "en"
# en = `trans :#{tagL} file://description.txt`
# # en = ""
# puts en
# puts en.length
# if en.length < 10
# puts "小于 10"
# en = File.read("description.txt")
# # en = afile.sysread(20)
# puts en
# end
def getAllLanguages
... | true |
2a551060ff76ebd883a3d369210f134e6e3afd47 | Ruby | dkaushal99352/devbootcamp | /rubyprogs/silverware.rb | UTF-8 | 3,070 | 4.09375 | 4 | [] | no_license | class Drawer
attr_reader :contents
# Are there any more methods needed in this class?
def initialize
@contents = []
@open = true
@lock = false
end
def open #opens Drawer
if @locked
puts "Drawer is locked and cannot be open"
else
@open = true
puts "Drawer has been opened"
end
end
... | true |
097c62f49e4abbff4b1133c10a93034618fa70fb | Ruby | EliahKagan/crystal-sketches | /blockproc.rb | UTF-8 | 315 | 2.984375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"0BSD"
] | permissive | #!/usr/bin/env ruby
# frozen_string_literal: true
$VERBOSE = 1
# Extensions for objects that are sequences of integers.
class Object
def evens
self.select(&:even?)
end
def each_even(&block)
evens.each { |x| block.call x }
end
end
if __FILE__ == $PROGRAM_NAME
(1..76).each_even { |x| p x }
end
| true |
13d033208a56715e2434e00a20171143d940a91f | Ruby | kkkw/ruby-pwauth | /pam-ruby.rb | UTF-8 | 392 | 2.734375 | 3 | [] | no_license | require 'open3'
class PamPWAuth
def authenticate(login, password)
o,e,status = Open3.capture3('pwauth', :stdin_data =>"#{login}\n#{password}")
puts o
puts e
puts status
return nil unless status.success?
return true
end
end
auth = PamPWAuth.new()
puts "start"
if auth.a... | true |
bbab31398c4a070845b9dd39cd80a520c827007c | Ruby | Sonna/toy-robot | /test/toy_robot/cell_test.rb | UTF-8 | 1,919 | 2.984375 | 3 | [] | no_license | require "test_helper"
module ToyRobot
class CellTest < Minitest::Test
BooBazGrid = Struct.new(:min, :max)
class BooBazEntity
def draw
"E"
end
end
class FooFangEntity; end
def described_class
Cell
end
class DescribeInstanceMethods < CellTest
def setup
... | true |
ffcc5eb8cbf7de4de5a5bff514603af95709a12e | Ruby | jwon114/wdi14_warmups | /week04/brain_gym/thu_21_dec.rb | UTF-8 | 1,079 | 4.125 | 4 | [] | no_license | # Print out all the leap years in the last 100 years.
# For numbers between 0 and 200:
require "pry"
require "Date"
require "Prime"
def is_leap_year()
current_year = Date.today.year
first_year = current_year - 100
year_arr = []
for year in first_year .. current_year
if (year % 4 == 0 && year % 100 != 0) || ye... | true |
83d61d12b92a5638dce8a243cb4c695fb3366445 | Ruby | Dale-R-Harrison/RB101 | /small_problems/easy4/multiples_of_three_and_five.rb | UTF-8 | 290 | 3.6875 | 4 | [] | no_license |
def multisum(integer)
multiples = []
(1..integer).each do |element|
if element % 3 == 0 || element % 5 == 0
multiples << element
end
end
multiples.reduce(:+)
end
puts multisum(3) == 3
puts multisum(5) == 8
puts multisum(10) == 33
puts multisum(1000) == 234168
| true |
aea4e4bb1aa87461c15975c8ef13b9f0dd57803e | Ruby | usman-tahir/rubyeuler | /factorial.rb | UTF-8 | 158 | 3.734375 | 4 | [] | no_license | # http://rosettacode.org/wiki/Factorial
def factorial(number)
if number <= 1
1
else
number * factorial(number-1)
end
end
p factorial(5) | true |
2987033309827ccf35132bf2b46d2a80c7dc5578 | Ruby | ruby-dlib/ruby-dlib | /examples/dnn_face_detection.rb | UTF-8 | 977 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'dlib'
image_file = ARGV[0] || 'ext/dlib-19.4/examples/faces/2009_004587.jpg'
# you can download model file from http://dlib.net/files/mmod_human_face_detector.dat.bz2
model_file = 'mmod_human_face_detector.dat'
detector = Dlib::DNNFaceDetector.new(model_file)
puts 'single detections'
img = Dlib::Image.load... | true |
cc6e0eb570d3270811d77c3bb827906d683c591f | Ruby | cucumber/aruba | /lib/aruba/matchers/file/have_file_size.rb | UTF-8 | 1,168 | 2.796875 | 3 | [
"MIT"
] | permissive | # @!method have_file_size(size)
# This matchers checks if path has file size
#
# @param [Fixnum] size
# The size to check
#
# @return [Boolean] The result
#
# false:
# * if path does not have size
# true:
# * if path has size
#
# @example Use matcher
#
# RSpec.describe do
# it { ex... | true |
f46234e574c216a5040579af8929724126ff8b5b | Ruby | thebravoman/software_engineering_2013 | /class8_1_homework/Logicless/cars_task_3.rb | UTF-8 | 648 | 3.09375 | 3 | [] | no_license | #/usr/bin/ruby
require 'csv'
list = File.open("car_sort.csv", "w")
list.write 'Varna'
if ARGV[0] == 'cars.csv'
CSV.foreach(ARGV[0]) do |row|
if ARGV[1].length == 1
if row[0][0] == ARGV[1]
row[0][0] == ARGV[1]
list.puts
list.w... | true |
c1a3868612f483bdf4258ebc1416afa55d8d5ceb | Ruby | ngmaloney/jekyll-page-posts | /page_posts.rb | UTF-8 | 849 | 2.828125 | 3 | [] | no_license | module PagePosts
class Generator < Jekyll::Generator
def generate(site)
site.pages.each do |page|
PagePostGenerator.generate!(page, site)
end
end
class PagePostGenerator
attr_accessor :page, :site
def self.generate!(page, site)
self.new(page, site).add_posts
... | true |
34b789100c2485e020df13a2275d12ffa8eb6c9d | Ruby | mellowstoked/rspec | /03_simon_says/simon_says.rb | UTF-8 | 874 | 3.9375 | 4 | [] | no_license | def echo(string)
string
end
def shout(string)
string.upcase
end
def repeat(string, n=2)
if n == 2
string.prepend(string + " ")
elsif n > 2
newString = string * n
i = 1
spot = string.length
while i < n || spot < newString.length
if i == 1
newString.insert(spot, " ")
sp... | true |
fa0c753fdf80ac330f85f2d5c65c5f27c718fa0c | Ruby | DavidGmezHdez/PDOO | /CivitasRuby/lib/jugador.rb | UTF-8 | 9,480 | 2.734375 | 3 | [] | no_license | # encoding:utf-8
require_relative 'dado'
require_relative 'diario'
require_relative 'sorpresa'
require_relative 'titulo_propiedad'
module Civitas
class Jugador
@@CASAS_MAX = 4
@@HOTELES_MAX = 4
@@CASAS_POR_HOTEL = 4
@@PASO_POR_SALIDA = 1000
@@PRECIO_LIBERTAD = 200
@@SALDO_INICIAL = 7500... | true |
4aeffc2c57448194406305d5454e0efa53cdd9c4 | Ruby | njch5/reverse-sentence | /lib/sort_by_length.rb | UTF-8 | 599 | 4.21875 | 4 | [] | no_license | # A method which will return an array of the words in the string
# sorted by the length of the word.
# Time complexity: O(n^2) n is the split_sentence array which gets iterated over until there are no more elements left
# Space complexity: O(n) n is for the sorted array which takes up additional space
def sort_by_leng... | true |
8b147866c3da1aa36c4da302c1bc5fc0f0eea98f | Ruby | onerobotics/tp_plus | /lib/tp_plus/nodes/position_data_node.rb | UTF-8 | 2,166 | 2.6875 | 3 | [
"MIT"
] | permissive | module TPPlus
module Nodes
class PositionDataNode < BaseNode
attr_reader :hash
def initialize(hash)
@hash = hash
@ids = []
end
def valid?
return false unless @hash[:positions].is_a?(Array)
return false if @hash[:positions].map {|p| position_valid?(p) == fa... | true |
529c6e80b0372c3a05be43a41df569a0505e4483 | Ruby | cpsoinos/Practice | /todo_list/server.rb | UTF-8 | 1,245 | 2.765625 | 3 | [] | no_license | require "sinatra"
require "pg"
# get "/hello" do
# "<p>Hello, world! The current time is #{Time.now}.</p>"
# end
def db_connection
begin
connection = PG.connect(dbname: "todo")
yield(connection)
ensure
connection.close
end
end
get "/tasks" do
# tasks = File.readlines("tasks.txt")
tasks = db_c... | true |
d31b9ec10720ce05bb7f0bb419a08f25cd18f9b0 | Ruby | SimonGlancy/BorisBikes | /lib/testScript.rb | UTF-8 | 147 | 2.875 | 3 | [] | no_license | require_relative 'docking_station'
dock = DockingStation.new
while true
bk = Bike.new
puts "storing bike n#{bk}"
dock.return_bike(bk)
end
| true |
371b700b7e30e042561c6784400dc0cdba726e48 | Ruby | hooleyhoop/JavascriptStuff | /app/helpers/hoo_gui_helper.rb | UTF-8 | 4,758 | 2.53125 | 3 | [] | no_license | module HooGuiHelper
# add object to the viewstack
def push( obj )
if obj.nil?
raise "cant push nil onto the view stack"
end
viewStack = self.instance_variable_get("@hooViews");
if viewStack.nil?
viewStack = Array.new()
self.instance_variable_set( "@hooViews", viewStack )
end
viewStack << obj
... | true |
f027067c06bf825139f85af50de05b2e682b156f | Ruby | ntkhoi/exercism_solution | /hamming/hamming.rb | UTF-8 | 235 | 3.5 | 4 | [] | no_license | class Hamming
def self.compute(str1, str2)
raise ArgumentError if str1.length != str2.length
count = 0
str1.split('').each_with_index do |c, i|
count += 1 if str2.split('')[i] != c
end
count
end
end | true |
814a3dfb3c856d512dda0015d4d35ffd48a7d2f7 | Ruby | fidothe/ofx-data | /lib/ofx/data/banking/transaction.rb | UTF-8 | 1,891 | 2.578125 | 3 | [
"MIT"
] | permissive | require "bigdecimal"
require "digest/sha1"
module OFX
module Data
module Banking
class Transaction
FIELDS = [:type, :date_posted, :amount, :bank_account_to, :name, :refnum, :payee_id, :memo].freeze
VALID_TYPES = [
:credit, :debit, :int, :div, :fee, :srvchg, :dep, :atm, :pos, :xfer... | true |
6cca5d5a571c1d675ada2616ecd5f766eaae5e89 | Ruby | thomasbaustert/periods | /spec/lib/month_spec.rb | UTF-8 | 2,883 | 3 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'periods/constants'
require 'initialized_by_single_date'
describe Month do
let(:subject) { described_class.for("1.1.2015") }
it_behaves_like "Initialized by single date" do
let(:period) { described_class.for(Date.new(2015,6,25)) }
end
describe "#next" do
it "returns nex... | true |
cd8be15fcbd3fdc19ed1026be27db9238faec9f5 | Ruby | kelseybjames/assignment_oop_warmups_1 | /my_inject.rb | UTF-8 | 414 | 3.578125 | 4 | [] | no_license | class Array
def my_inject(input, proc_argument=nil) # ask about input shown as 0
i = 0
inject_result = input
until i == self.length
if block_given?
inject_result = yield(inject_result, self[i])
else
inject_result = proc_argument.call(inject_result, self[i])
end
i +=... | true |
37ee9a5a0534cc41bd4fc96c00bdecb4aac85363 | Ruby | dwwickman/phase-0-tracks | /ruby/shout.rb | UTF-8 | 763 | 4 | 4 | [] | no_license | # module Shout
# def self.yell_angrily(words)
# words + "!!!" + " :("
# end
# def self.yell_happily(words)
# words + "!!!" + " :)"
# end
# end
# puts Shout.yell_angrily("SO MAD")
# puts Shout.yell_happily("SO HAPPY")
module Shout
def yell_angrily(words)
words.upcase + "!!!" + " :("
end
def... | true |
b621530aa20f0e863e0b964a91bbdde3fb3069e1 | Ruby | trunkslamchest/apis-and-iteration-dumbo-web-091619 | /lib/command_line_interface.rb | UTF-8 | 346 | 3.03125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def welcome
puts "Welcome message, here!"
end
def get_character_from_user
puts "Please enter a Character name"
input = gets.strip.downcase
# binding.pry
end
# def get_character_from_user
# puts "Please enter a Character name"
# input = gets.strip
# # binding.pry
# end
# get_character_fr... | true |
8fa8b05f9f28b6a1b872608e30fc02f42185fd3d | Ruby | AkanshaVaish/DineForTwo | /app/helpers/restaurants_helper.rb | UTF-8 | 693 | 2.59375 | 3 | [] | no_license | module RestaurantsHelper
# Returns the current logged in user.
def current_user
if (person_id = session[:person_id])
# If a temporary session exists, use that.
@current_user ||= Person.find_by(id: person_id)
elsif (person_id = cookies.signed[:person_id])
# If cookies exist, use them.
... | true |
b1c8fc5d8b009a72bc0f292b2d0a8103490c0738 | Ruby | vanstee/celluloid_and_dcell | /dcell_walkthrough.rb | UTF-8 | 668 | 2.609375 | 3 | [] | no_license | require 'dcell'
DCell.start(id: 'atlrug', addr: 'tcp://0.0.0.0:7777')
# Other nodes can connect with:
#
# DCell.start(
# id: "atlrug_#{name}",
# directory: {
# id: 'atlrug',
# addr: "#{IPSocket.getaddress(Socket.gethostname)}"
# }
# )
class Counter
include Celluloid
attr_reader :count
def initi... | true |
b8bc9de49c5c50b315480f5ce252af849bb6f016 | Ruby | chad/rubinius | /tools/tracer.rb | UTF-8 | 1,465 | 2.859375 | 3 | [] | no_license |
# Example Usage:
#
# ruby -Itools -rtracer blah.rb > spec/profiles/blah.yaml
require 'yaml'
class Tracer
@@stdout = STDOUT
EVENT_SYMBOL = {
:call => ">",
:class => "C",
:"c-call" => ">",
}
def initialize
# @counts[klass][method] += 1
@counts = Hash.new { |h,k| h[k] = Hash.n... | true |
c385530c08c155168d5e8d6fddc14b48be190ec2 | Ruby | rkoopmanschap/online_evolution | /world.rb | UTF-8 | 3,752 | 3.34375 | 3 | [] | no_license | class World
attr_reader :species
def initialize
@species = []
@gene_pool = GenePool.new
@plants = STARTING_PLANTS
@insects = STARTING_INSECTS
@fish = STARTING_FISH
NUMBER_OF_SPECIES.times do
@species.push(Species.new(@gene_pool))
end
end
# ====================
public
# ====================... | true |
7e2e86e4ba17b263422db0d260df16d5d87daf20 | Ruby | HannahBB/beer_exercise | /beer.rb | UTF-8 | 448 | 4.75 | 5 | [] | no_license | require 'pry'
#write a function that accepts a variable: age
#if age is greater than 21, display "Yay, have a beer!"
#if age is less than 21, display "Nay, don't have a beer!"
#ask for the user's age
#store the user input in a variable: user_age
#run the function
def drinking(age)
if age > 21
puts "yay, ge... | true |
9e58ce17db6dd1f62c7c66e248029cb5c4dc0d4d | Ruby | KatherineGuenther/sinatra-helpers-demo | /helpers/session.rb | UTF-8 | 410 | 2.609375 | 3 | [] | no_license | # Just an Example this sample doesn't have a User database
helpers do
def set_current_user user
@user = user
session[:user_id] = @user.id
end
def current_user
if session[:user_id]
@user ||= User.find(session[:user_id])
else
@user = nil
end
end
def authenticated?
!curr... | true |
e451419d71eb40a2644d92bbf58a23d4a819d6fd | Ruby | whyarkadas/http_ping | /lib/HttpPing/wmi.rb | UTF-8 | 4,286 | 2.6875 | 3 | [
"MIT"
] | permissive |
require File.join(File.dirname(__FILE__), 'ping')
require 'win32ole'
# The Net module serves as a namespace only.
#
module HttpPing
# The Ping::WMI class encapsulates the Win32_PingStatus WMI class for
# MS Windows.
#
class HttpPing::WMI < Ping
PingStatus = Struct.new(
'PingStatus',
:add... | true |
ac59fe4921f95496bab8372f09184176b4c49e71 | Ruby | caarlosdamian/ruby_basics | /Chapter_11/11.3.rb | UTF-8 | 524 | 3.03125 | 3 | [] | no_license | def music_shuffle arr
end
music_shuffle ['asd/asd.ccc', 'g/dd.ccc', 'vv/ddd.ccc'] ''
song_name= Dir['C:/Users/Eduardo/Music/**/*.m4p']
puts 'What would you like to call your playlist?'
playlist_name = gets.chomp
song_list = []
song_name.each do |name|
song_list.push name
end
filename = playlist_name+'.m3u'
shuff... | true |
0e36dba8b4dbdb475702e3cbc20eee5bc305cb9d | Ruby | dbsk11/dumbo-se-030920 | /10-intro-to-testing/roman_numeral_translator.rb | UTF-8 | 766 | 3.640625 | 4 | [] | no_license | require 'pry'
class RomanNumeralTranslator
ROMAN_TO_ARABIC = {
"M" => 1000,
"D" => 500,
"C" => 100,
"L" => 50,
"X" => 10,
"V" => 5,
"I" => 1
}
ARABIC_TO_ROMAN = {
1000 => "M",
500 => "D",
100 => "C",
50 => "L",
10 => "X",
5 => "V",
1 => "I"
}
def sel... | true |
07e7e7adc8918d49d22759a0c1b79a027e039e33 | Ruby | mattbrictson/chandler | /lib/chandler/logger.rb | UTF-8 | 1,750 | 2.984375 | 3 | [
"MIT"
] | permissive | require "chandler/refinements/color"
module Chandler
# Similar to Ruby's standard Logger, but automatically removes ANSI color
# from the logged messages if stdout and stderr do not support it.
#
class Logger
using Chandler::Refinements::Color
attr_accessor :stderr, :stdout
def initialize(stderr: ... | true |
54b1b358b97ebbc00bc3cb871bd3aa675614920f | Ruby | m11o/algorithms | /ruby/src/data_structures/priority_queue/priority_queue.rb | UTF-8 | 584 | 3.328125 | 3 | [
"MIT"
] | permissive | require_relative '../heap/min_heap'
class PriorityQueue < MinHeap
def initialize
super
@priorities = {}
end
def add(value, priority)
@priorities[value] = priority
super value
self
end
def change_priority(value, priority)
remove value
add value, priority
self
end
def rem... | true |
5edbc5de2e67b73ce4586f7675e44ab594375ed5 | Ruby | codyruby/cursus_thp | /week3/the_hacking_gossip_ruby_version_POO/lib/view.rb | UTF-8 | 468 | 3.09375 | 3 | [] | no_license | class View
def create_gossip
puts 'Bonjour, quel est ton nouveau gossip ?'
puts 'Quel est ton nom :'
@author = gets.chomp
puts 'Quel est ton gossip :'
@content = gets.chomp
params = { author: @author, content: @content }
return params
end
def self.index_gossips(array_to_... | true |
b05e318dddbbbe4ae268f639dea2b78e14e147bf | Ruby | itsolutionscorp/AutoStyle-Clustering | /assignments/ruby/hamming/src/448.rb | UTF-8 | 113 | 3.03125 | 3 | [] | no_license | def compute(s1, s2)
paired = s1.chars.zip(s2.chars)
paired.count do |p1, p2|
p1 != p2
end
end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.