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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5982724dbec6e12e0057439c8a6a396661fc227a | Ruby | sharonshlee/TwO-O-Player_Math_Game | /player.rb | UTF-8 | 211 | 3.34375 | 3 | [] | no_license | class Player
attr_accessor :lives
attr_accessor :name
def initialize(name)
@lives = 3
@name = name
end
def deduct_scores()
@lives -= 1
end
def to_s
"Player #{name}:"
end
end | true |
da141240dab17fb1bfe01a7b2c78a90f018f0faa | Ruby | lyhourlay1/aa_classwork | /w7/w7d5/reddit_clone/app/models/user.rb | UTF-8 | 1,022 | 2.578125 | 3 | [] | no_license | class User < ApplicationRecord
validates :username, :password_digest, :session_token, presence:true
validates :username, uniqueness:true
validates :password, length: {minimum: 6}, allow_nil: true
attr_reader :password
after_initialize :ensure_session_token
def password=(password)
@pas... | true |
85b883f72bb3e943d0b6fdafc32ce2aa9a4c31b7 | Ruby | IlluminusLimited/pgdice | /lib/pgdice/period_fetcher.rb | UTF-8 | 862 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module PgDice
# Used to find the period of a postgres table using the comment on the table created by pgslice
class PeriodFetcher
def initialize(query_executor:)
@query_executor = query_executor
end
def call(params)
sql = build_table_comment_sql(params.fetch(:... | true |
8c70d32d1c96e70a8677f04bd8f649a666e0b837 | Ruby | Sayantini11/Ruby | /array_largest.rb | UTF-8 | 264 | 3.765625 | 4 | [] | no_license | puts "Enter the size of the array"
size = gets.chomp.to_i
puts "Enter the array element"
arr = []
i = 0
while i < size
arr[i] = gets.chomp.to_i
i += 1
end
max_value = 0
arr.each do |i|
if i > max_value
max_value = i
end
end
puts "Max value is #{max_value}"
| true |
c46dba40b295707c2945d79711b723efbfe248ef | Ruby | realalien/rubyplayground | /news.tool/yangtze_collector.rb | UTF-8 | 3,680 | 2.984375 | 3 | [] | no_license | #encoding:UTF-8
require 'date'
require 'nokogiri'
require 'json'
require File.join(File.dirname(__FILE__),"./util.rb")
class YangtzeDailyCollector
# NOTE: because the section/page-titles and article-titles are among different rows of the same table, data will be gathered by processing each row sequentially.... | true |
a7e8b19d45e54d5a4033dfde3878b1c8cfa7974b | Ruby | gautamsawhney/BrainStorm | /app/models/level.rb | UTF-8 | 549 | 2.5625 | 3 | [] | no_license |
class Level < ActiveRecord::Base
attr_accessible :answer, :next_id, :prev_id, :question, :image
before_save :sterlize_answer
mount_uploader :image, ImageUploader
has_many :attempts
validates :answer , :presence => true, :length => {:maximum => 50}
def self.set(params)
next_id = nil
prev_id =... | true |
643e367fc42fab20ac287cfb2b2774f9ab775bad | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/675480c69bef443589571311cf592828.rb | UTF-8 | 619 | 3.484375 | 3 | [] | no_license | class Bob
# Approach taken from Bozhidar Batsov's recent blog post:
# http://batsov.com/articles/2013/09/24/lambdas-slash-procs-in-case-expressions/
def hey(message)
case message
when silence?
'Fine. Be that way!'
when shout?
'Woah, chill out!'
when question?
'Sure.'
else
... | true |
03cf20274a3b48762dffe619728118ce0afd4815 | Ruby | a-gerlach/LaunchSchool_101_Programming_Foundations | /lesson_4/loop_improvement_21.rb | UTF-8 | 8,846 | 4.15625 | 4 | [] | no_license | require "pry"
# we initialize the deck as an Array containing every card of every color.
DCK = ["2heart", "3heart", "4heart", "5heart", "6heart", "7heart", "8heart", "9heart", "10heart", "jackheart", "queenheart", "kingheart", "aceheart",
"2dia", "3dia", "4dia", "5dia", "6dia", "7dia", "8dia", "9dia", "10dia", "jackdi... | true |
b6a359ddfc28dbe91cf111f51df2a727fcf315cd | Ruby | njenga-kariuki/sql-crowdfunding-lab-seattle-web-career-021819 | /lib/sql_queries.rb | UTF-8 | 2,056 | 3.109375 | 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.
def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabe... | true |
451aeae27c2820ae08a98449df91c9eca8591c10 | Ruby | Scoutski/adventOfCode2018 | /day5q2/solution.rb | UTF-8 | 1,196 | 3.5 | 4 | [] | no_license | def extractLinesFromFile (fileName)
return IO.readlines(fileName)
end
def testCharacters (line)
shortestPolymer = 999999999
testedChars = []
for i in 0..(line.length-1) do
if line[i].is_a?(String)
if !testedChars.include? line[i]
testedChars.push(line[i].downcase, line[i].upcase)
lin... | true |
f88babda1aab485929097108948b0b3a30baf377 | Ruby | amunguia/poker | /app/models/game.rb | UTF-8 | 13,315 | 2.890625 | 3 | [] | no_license | require 'json'
class Game < ActiveRecord::Base
belongs_to :table
def initialize(min_bet)
super()
deck = Deck.new_deck
self.stream = deck.slice(0,5).join ","
self.p1_cards = deck.slice(5,2).join ","
self.p2_cards = deck.slice(7,2).join ","
self.p3_cards = deck.slice(9,2).join ","
s... | true |
2b31d1b45428f1f9e03f7e86b0b4abe4b21cde21 | Ruby | dscottcole/ruby-oo-object-relationships-collaborating-objects-lab-hou01-seng-ft-071320 | /lib/variables.rb | UTF-8 | 1,237 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require_relative './artist'
require_relative './song'
require_relative './mp3_importer.rb'
# elton = Artist.new("Elton John")
# yoursong = Song.new("Your Song")
# yoursong.artist_name = ("Elton John")
# artist = Artist.new('Michael Jackson')
# dirty_diana = Song.new("Dirty Diana")
# billie_jean = Song... | true |
ee343a38be08d0f3807cb74602fdcfc730aabbf9 | Ruby | matiasgarcia/cabify_challenge | /lib/cabify_challenge/line_item.rb | UTF-8 | 417 | 2.8125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module CabifyChallenge
class LineItem
attr_reader :product, :quantity, :checkout
def initialize(product:, quantity: 0, checkout:)
@product = product
@quantity = quantity
@checkout = checkout
end
def add
@quantity += 1
end
def total
... | true |
d2de051d6da5be4da92dd14f73239d86be7ec7b5 | Ruby | NikitaSmall/ruby-lessons | /vasya-bot/lib/greeter.rb | UTF-8 | 320 | 3.15625 | 3 | [] | no_license | class Greeter
def self.run(message)
{ chat_id: message.chat.id, text: message_text(message) }
end
def self.message_text(message)
case message.text.downcase
when 'hello', '/start'
"Hello, #{message.from.first_name}"
when '/stop'
"Farewell, #{message.from.first_name}"
end
end
end
| true |
83d31c0a5b35b619fad58792e53d2313de95b824 | Ruby | dantrovato/launch-school | /lesson_4/loop_experiments/double_odd_numbers.rb | UTF-8 | 1,566 | 4.84375 | 5 | [] | no_license | # We previously said that transformation is an operation that is performed on every element in the collection. In the next example, we'll study a method that only transforms a subset of the elements in the collection. Here, we only multiply by 2 if the value is odd. The if condition will only evaluate to true if curren... | true |
ef46cec981304aa2df85efeded3c75ef36fa82f6 | Ruby | hleeldc/jira-ticket-graph | /scripts/harvest.rb | UTF-8 | 427 | 2.859375 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
require 'json'
require 'dbm'
def get_db
db_file = ARGV[0]
db = DBM::open(db_file, DBM::WRCREAT)
return db
end
def update_db(db, jira_data)
jira_data['issues'].each do |issue|
key = issue['key']
db[key] = issue.to_s
puts "--#{key}"
end
end
def test
db = get_db
file = File.open(ARG... | true |
e6369b2cb84f93e35e8c0998dfcd08ab40d1fa6d | Ruby | Rockster160/Portfolio | /app/service/bowling_stats.rb | UTF-8 | 4,781 | 2.640625 | 3 | [] | no_license | class BowlingStats
def self.pickup(bowler, str_pins)
new(nil).pickup(bowler, str_pins)
end
def self.pickup_stats_by_name(bowler_name, str_pins)
new(nil).pickup_stats_by_name(bowler_name, str_pins)
end
delegate :pickup, to: :class
def initialize(league, set=nil)
@league = league
@set = se... | true |
67eaac8fda4e636f991f9d9a1de844f4102779be | Ruby | armi1189/ruby-kickstart | /session2/3-challenge/3_array.rb | UTF-8 | 341 | 4.125 | 4 | [
"MIT"
] | permissive | # Write a method named every_other_char for strings that,
# returns an array containing every other character
#
# example:
# "abcdefg".every_other_char # => "aceg"
# "".every_other_char # => ""
class String
def every_other_char
ret = ""
self.split('').each_with_index {|x, y| if y.even?; ret << x; en... | true |
1aa9d5b97815c52c975148c4ce4a5dc5e6d561a6 | Ruby | fmorales/flor | /lib/flor/pcore/define.rb | UTF-8 | 1,440 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
class Flor::Pro::Define < Flor::Procedure
#
# Defines a function.
#
# In its `define` flavour, will take a function body and assign it to
# variable.
# ```
# define sum a, b # make variable 'sum' hold the function
# +
# a
# b
# # yields the function, like `fun` and `def` do
#
# su... | true |
336959b1dd58736d86c27e95dd25947eee7b69a5 | Ruby | ivanpilot/tweet | /app/lib/api_constraints.rb | UTF-8 | 497 | 2.6875 | 3 | [] | no_license | class ApiConstraints
attr_reader :version, :default
def initialize(version, default = false)
@version = version
@default = default
end
def matches?(request)
version = check_headers(request.headers) || default
# binding.pry
version
end
def check_headers(headers)
accept = headers[:... | true |
1ad8646020d1bf6d29c4dfd66de0a48b2cdef429 | Ruby | Chanson9892/programming-univbasics-nds-green-grocer-part-1-sea01-seng-ft-082420 | /lib/grocer.rb | UTF-8 | 607 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def find_item_by_name_in_collection(name, collection)
index = 0
collection.each do |item|
if item[:item] == name
return item
end
index += 1
end
nil
end
def consolidate_cart(cart)
new_cart = []
cart.each do |grocery_item|
current_item = find_item_by_name_in_collection(grocery_item[:ite... | true |
42a65d4388d1a591108e545d4f56aeab53e38b36 | Ruby | laamia/glassdoor_scraper | /lib/glassdoor_scraper/scraper.rb | UTF-8 | 1,422 | 2.609375 | 3 | [] | no_license | class GlassdoorJobs::Scraper
def self.get_page(url)
Nokogiri::HTML(open(url))
end
def self.get_job_list(url)
self.get_page(url).css("div.jobTitleContainer.cell.middle")
end
def self.create_jobs(url)
self.get_job_list(url).each do |job|
company = job.css("div.small").text
salary = jo... | true |
9f823acb24b3fb27c28802968a9b5ce8dcfe9def | Ruby | ZhenyingZhu/StudyNotes | /ruby-example/thread-args.rb | UTF-8 | 108 | 2.90625 | 3 | [] | no_license | #! /bin/env ruby
arr = []
a, b, c = 1, 2, 3
Thread.new(a, b, c) { |d, e, f| arr << d << e << f }.join
arr
| true |
2e249a2a3d45975e98ccb02b8ecc9e1907d7a70f | Ruby | mallibone/SeriesNamer | /lib/renamer.rb | UTF-8 | 1,629 | 2.890625 | 3 | [] | no_license | module SeriesNamer
require_relative 'find_episodes'
require_relative 'get_episode_names'
require_relative 'parse_path'
require_relative 'rename_episodes'
class Renamer
attr_reader :path, :series_info
@dir #defaults to ruby dir used for tests
@file #defaults to ruby file used for tests
def... | true |
91667692f928c51c20bb8be5bd5d96fe34094418 | Ruby | aussiDavid/obvious | /spec/contract_spec.rb | UTF-8 | 1,724 | 2.796875 | 3 | [
"MIT"
] | permissive | require_relative 'spec_helper'
require_relative '../lib/obvious/contract'
describe Hash do
describe '#has_shape?' do
it 'should return true for a valid shape' do
{ id: 1 }.has_shape?(id: Fixnum).should be true
end
it 'should return false for an invalid shape' do
{ id: 1 }.has_shape?(id:... | true |
816bc0418e73732b18864f0c46f4b6655b6262ef | Ruby | ksummerill/ttt-5-move-rb-online-web-sp-000 | /lib/move.rb | UTF-8 | 663 | 4.34375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | 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 input_to_index
# converts a user_input to an integer ("5" becomes 5)
# subtracts 1 ... | true |
d5d2ce5992c2d0b19cbc21a058df45a61eeabfb1 | Ruby | aahmad94/algorithm_projects | /05_binary_search_tree/lib/binary_search_tree.rb | UTF-8 | 2,988 | 3.46875 | 3 | [] | no_license | # There are many ways to implement these methods, feel free to add arguments
# to methods as you see fit, or to create helper methods.
require 'bst_node'
class BinarySearchTree
attr_reader :root
def initialize
@root = nil
end
def insert(value)
unless @root
@root= BSTNode.new(value)
retu... | true |
8638b3a7314ec134371592d931cfd4f542a6791c | Ruby | Shopify/giffy | /lib/giffy/pipeline.rb | UTF-8 | 316 | 2.8125 | 3 | [
"MIT"
] | permissive | module Giffy
class Pipeline
attr_reader :processors
def initialize(processors)
@processors = processors
end
def process(input, options)
processors.reduce(input) do |input, processor|
instance = processor.new(options)
instance.process(input)
end
end
end
end
| true |
e53b6a037ad3ae74e3987ca1226ad7722707f3e1 | Ruby | ozeron/casting | /test/actor_test.rb | UTF-8 | 520 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require_relative '../src/actor'
class ActorTest < MiniTest::Unit::TestCase
def setup
@speech = Casting::Speech.new "Great Title", "Great Text"
@actor = Casting::Actor.new :m, 20, @speech
end
def test_new_initialize
title = "Thats "
text = "it!"
@act = Casting::Actor.new :f,18, t... | true |
1dc9453d5417075845da58271fd3b24a8a8aa300 | Ruby | KhalilC/collections_practice_vol_2-001-prework-web | /collections_practice.rb | UTF-8 | 1,068 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # your code goes here
def begins_with_r(collection)
collection.all? {|tool| tool[0] == 'r' }
end
def contain_a(collection)
collection.select {|word| word.include?('a')}
end
def first_wa(collection)
collection.each {|word| return word if word[0..1] == "wa"}
end
def remove_non_strings(collection)
collection.se... | true |
3c86fdac20304257f6666ce0715c4ac596cdcec2 | Ruby | lechris1/theodinproject | /webdevelopment101/projecteuler/prob2.rb | UTF-8 | 177 | 3.28125 | 3 | [] | no_license | sum = 0
n1, n2 = 1, 2
next_num = n1+n2
sum += n2
while next_num < 4000000
if next_num%2==0
sum += next_num
end
n1 = n2
n2 = next_num
next_num = n1+n2
end
puts sum
| true |
e934fb3f84a9cd71844856a0f37bfe19596902a3 | Ruby | amitdoshi93/SimpleStartupNameGenerator | /generate.rb | UTF-8 | 768 | 3.578125 | 4 | [] | no_license | def startup
puts "Enter the number of letters you want in your startup name:"
n_letters = gets.chomp.to_i
end
n_letters = startup
unless n_letters>1
puts "The number should be more than 1!"
n_letters = startup
end
puts "Now enter positions where you want your vowels starting from 1"
vowels = gets.chomp().split(","... | true |
9ac1046fe3c375c2b40dcc63f2fd891c8d5c3936 | Ruby | Markentoine/codewars | /ruby/airstrike.rb | UTF-8 | 1,906 | 4.03125 | 4 | [] | no_license | =begin
Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters.
The tension between left side letters and right side letters was too high and the war began.
The letters called airstrike to help them in war - dashes and dots are spreaded everywhere on the battlefield.
... | true |
817010386088ee2ea6f2384fec68f9f09347a43a | Ruby | mindless/dm-sinatra-security | /lib/sinatra/security/login_field.rb | UTF-8 | 1,738 | 2.71875 | 3 | [
"MIT"
] | permissive | module Sinatra
module Security
# This module allows you to customize the name of the login field used
# in your datastore. By default :email is used.
#
# @example
#
# # somewhere in your code during bootstrapping
# require 'sinatra/security'
# Sinatra::Security::LoginField.att... | true |
ad5b691d3bfc4737b90b0889fd8250fd9dc6cc47 | Ruby | Bonemind/D3Edps | /edps.rb | UTF-8 | 1,468 | 3.296875 | 3 | [] | no_license | # Weapon damage values
min_weapon = 1398
max_weapon = 1813
#Off-hand damage values
min_offhand = 461
max_offhand = 570
# Effective weapon damage
weapon_damage = ((min_weapon + min_offhand + max_weapon + max_offhand)/2.0)
# Primary stat (Int, Dex, etc.)
primary_stat = 10102
# Attack speed
attack_speed = 1.4
# The b... | true |
fb4e3442e332fe0af0056e3a30b2efe68d46f71e | Ruby | chuck0523/atCoder | /practise-ruby/inject-array.rb | UTF-8 | 100 | 3.109375 | 3 | [] | no_license | array = [1, 2, 3]
puts [1, 1, 1].inject(array) {|sum_array, a| sum_array << a}
# [1, 1, 1, 1, 2, 3]
| true |
b6a9b50ec1f0312a1a1e3fa0725fda06505ec81d | Ruby | RudeWalrus/PatentAgent | /spec/patentagent/patentagent_spec.rb | UTF-8 | 1,725 | 2.765625 | 3 | [] | no_license | require 'spec_helper'
module PatentAgent
describe PatentAgent do
context "#validate_patent_numbers" do
let(:all_good) { %w[US5551212 6661113 us8081555.b1 Us7776655.A1] }
let(:all_bad) { %w[US9551212 661113 2081555.b1 b3] }
it "accepts an array, returns array" do
result = Patent... | true |
35f79c6d1ed053610c43095cd0c269e419df4a0e | Ruby | Garima1125/ruby-maths-game | /main.rb | UTF-8 | 1,710 | 3.796875 | 4 | [] | no_license | require_relative 'player'
require_relative 'question'
#REPL + game logic
@repl_bool = true
#0 for p1 1 for p2
@turn = 0
puts "Welcome to ruby_math_game (OOP edition)"
puts
print 'Player 1 name: '
@username = gets.chomp
p1 = Player.new(@username)
p1.name = p1.name
print 'Player 2 name: '
@username = gets.chomp
p2 = P... | true |
36a27611bf709ca9cc86332b84f6907146572f34 | Ruby | Snerzel/programming-univbasics-4-square-array-online-web-prework | /lib/square_array.rb | UTF-8 | 186 | 3.03125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(array)
# your code here
new_numbers = []
counter = 0
while counter < array.length do
new_numbers << array[counter] ** 2
counter += 1
end
return new_numbers
end
| true |
9a0c01606a767d14da513d225aaef65b8966dd05 | Ruby | loriculberson/chisel | /lib/document_splitter.rb | UTF-8 | 130 | 2.703125 | 3 | [] | no_license | class DocumentSplitter
attr_reader :doc
def initialize(doc)
@doc = doc
end
def to_a
doc.split("\n\n")
end
end | true |
efb2c802f7b83926c31ecadcbbdaa5c48a9549e4 | Ruby | andywenk/page_performance | /lib/page_performance/utils/prerequisites.rb | UTF-8 | 538 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | module PagePerformance
module Utils
# check if everything in the environment is available to start the program
class Prerequisites
class << self
def check_prerequisites
ruby_version
phantomjs_available
end
def ruby_version
raise PagePerformance::Err... | true |
a1ac6214c68b6f78599d9bffdac780b4d4fa6059 | Ruby | kaidee/kaidee | /ruby/test.rb | UTF-8 | 60 | 2.765625 | 3 | [] | no_license | puts "#{1.0e3}"
# puts "0b10"
50.step(80,5){|i| print i," "} | true |
fe908240826deeca516f35bc576ce4d614387997 | Ruby | abracadabra89/rails-cru-form_for-lab-nyc-web-091619 | /db/seeds.rb | UTF-8 | 758 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
ef21699a7015c1d0b3607e1a6b8a514f71b5b14c | Ruby | jrharper224/RoR_April_2017 | /WilliamBlackwell/wiz_nin_sam/human.rb | UTF-8 | 380 | 3.53125 | 4 | [] | no_license | class Human
attr_accessor :strength, :intelligence, :health, :stealth
def initialize strength=3, intelligence=3, stealth=3, health=100
@strength = strength
@intelligence = intelligence
@stealth = stealth
@health = health
end
def attack(obj)
if obj.class.ancestors.include?(Human)
obj.he... | true |
6d1ca24aa6e3d45de0c5b9b566d2dd06dd02017b | Ruby | aws/aws-sdk-ruby | /gems/aws-sdk-core/spec/aws/token_spec.rb | UTF-8 | 846 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require_relative '../spec_helper'
module Aws
describe Token do
it 'provides access to the token' do
expect(Token.new('token').token).to eq('token')
end
it 'defaults the expiration nil' do
expect(Token.new('token').expiration).to be(nil)
end
it 'provid... | true |
a3e40eeba1cda294275884176e5c0b875c946f4a | Ruby | aman199002/Data-Structures-and-Algorithms-in-Ruby | /searching/first_bad_version.rb | UTF-8 | 513 | 3.546875 | 4 | [] | no_license | # The is_bad_version API is already defined for you.
# @param {Integer} version
# @return {boolean} whether the version is bad
# def is_bad_version(version):
# @param {Integer} n
# @return {Integer}
def first_bad_version(n)
left = 1
right = n
while right > left do
mid = left + (right - left)/2
... | true |
7f9c3db524e6a8feb19d8b6cd0e87cf8623c0cec | Ruby | booglysticks/ruby-tests | /kidsort.rb | UTF-8 | 666 | 4.5 | 4 | [] | no_license | # a little programme to find scattered children and line them up
# array of children
children = ['Titus', 'Angelica', 'Henry', 'Max', 'Alice', 'Hank', 'John', 'Ghost']
# sort array
puts 'I found these children'
puts children
# finding more children, until there are none left
while true
puts 'Did you find any mor... | true |
200bcc95c8bc06cfdaaf4eab8a06be872555d4b8 | Ruby | honorarac/vagrant | /plugins/commands/plugin/action/expunge_plugins.rb | UTF-8 | 2,280 | 2.53125 | 3 | [
"MIT"
] | permissive | require "vagrant/plugin/manager"
module VagrantPlugins
module CommandPlugin
module Action
# This middleware removes user installed plugins by
# removing:
# * ~/.vagrant.d/plugins.json
# * ~/.vagrant.d/gems
# Usage should be restricted to when a repair is
# unsuccessful and... | true |
0f3421b94bcdf0b96a59346301b1b6b023843957 | Ruby | minhajuddin/sessions2 | /ruby/def2.rb | UTF-8 | 207 | 3.625 | 4 | [] | no_license | def exec
f = Dog.new("Fido")
f.bark_twice
end
class Dog
def initialize(n)
@name = n
end
def bark_twice
bark
bark
end
def bark
puts @name + " says woof woof"
end
end
exec
| true |
d32d1dd5c2e2d1ad0dec38e852e95e1bbd5ef18f | Ruby | driscoll-brook-press/book-compiler | /lib/dbp/book_compiler/scriv2tex.rb | UTF-8 | 2,111 | 2.625 | 3 | [
"MIT"
] | permissive | require 'dbp/scrivener/project'
require 'dbp/book_compiler/util/cli'
require 'open3'
require 'yaml'
module DBP
module BookCompiler
class Scriv2TeX
include Open3
include CLI
HEADINGS = %w(wtf chapter scene)
def initialize
super 'scriv2tex'
end
def run
parse_... | true |
8a2f15088a7e4f9ff9b4eb259d13929a15222e4b | Ruby | mcwaller422/Intro_to_Ruby | /FlowControl/exercises/ex3.rb | UTF-8 | 260 | 4.15625 | 4 | [] | no_license | puts "Write a number, please"
number = gets.chomp.to_i
if number <=50
puts "Your number is less than, or equal to 50!"
elsif (number >50) && (number <100)
puts "Your number is between 51 and 100!"
else
puts "Your number is greater than 100!"
end
| true |
72b5bbd16c23d365cf4dde3be3b7c3a6d8a92578 | Ruby | michaelurquhart79/loops-and-hashes-lab- | /my_functions.rb | UTF-8 | 444 | 3.484375 | 3 | [] | no_license | def add_array_lengths (array1, array2)
array_plus_array = array1.length.to_i + array2.length.to_i
return array_plus_array
end
def sum_array(numbers)
counter = 0
for number in numbers
counter += number
end
return counter
end
def find_item(array, item)
for house in array
if house == item
... | true |
bd16192b3c60b20089d109e505f33ea94fd78e03 | Ruby | mkim4247/nyc-pigeon-organizer-dc-web-100818 | /nyc_pigeon_organizer.rb | UTF-8 | 693 | 3.078125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def nyc_pigeon_organizer(data)
pigeon_hash = {}
data.each do |main_stat, stat_name|
stat_name.each do |attribute, array|
array.each do |name|
pigeon_hash[name] = {:color => [], :gender => [], :lives => []}
end
end
end
data[:color].each do |color_name, pig_array|
pig_array... | true |
6e291c9fac34e184a5f3c35901a67e38dabbb258 | Ruby | alextfish/free-dom | /app/models/hinterlands/silk_road.rb | UTF-8 | 425 | 2.71875 | 3 | [] | no_license | class Hinterlands::SilkRoad < Card
victory {player.cards.select(&:is_victory?).count / 4}
costs 4
card_text "Victory (cost: 4) - Worth 1 point for every 4 Victory cards in your deck (round down)."
pile_size {|num_players| case num_players
when 1..2
8
... | true |
15e988bae8696cf97b075b92c10656cb3f7e70b2 | Ruby | rlee0525/Algorithms | /LeetCode/Problems/010_is_match.rb | UTF-8 | 2,358 | 3.640625 | 4 | [] | no_license | # '.' Matches any single character.
# '*' Matches zero or more of the preceding element.
# The matching should cover the entire input string (not partial).
# The function prototype should be:
# bool isMatch(const char *s, const char *p)
# Some examples:
# isMatch("aa","a") → false
# isMatch("aa","aa") → true
# isMat... | true |
0ec2454d584ab9872623a4ddeb16496c15812874 | Ruby | joshnevius/badges-and-schedules-v-000 | /conference_badges.rb | UTF-8 | 558 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def badge_maker(name)
return "Hello, my name is #{name}."
end
attendees = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def batch_badge_creator(attendees)
attendees.collect do |name|
badge_maker(name)
end
end
def assign_rooms(attendees)
attendees.each_with_index.map do |name, num|
"... | true |
d55ac5990dd28b1f0c6299f344d9f4c01447c0bb | Ruby | Jschles1/ttt-with-ai-project-v-000 | /lib/players/human.rb | UTF-8 | 249 | 3.203125 | 3 | [] | no_license | module Players
# Inherits from Player.
class Human < Player
# Asks the user for input and returns it.
def move(board)
print "Where would you like to move (1-9)? "
move_input = gets.chomp
move_input
end
end
end
| true |
5210278d1be2b6e3ea39904d571045baf4513dee | Ruby | iomelchenko/diff | /diff.rb | UTF-8 | 733 | 2.890625 | 3 | [] | no_license | class Diff
def initialize(compared_objects)
@compared_objects = compared_objects
end
def execute
show_result(sdiff_object)
end
def show_result(sdiff_object)
sdiff_object.each do |line|
line_number = (line.old_position + 1).to_s
if line.changed?
puts line_number + ' ' + '* ' +... | true |
212d6d70af1ad0f7730b7ffd562676ef1c360b92 | Ruby | jwworth/exercism | /ruby/resistor-color-duo/resistor_color_duo.rb | UTF-8 | 242 | 2.71875 | 3 | [] | no_license | module ResistorColorDuo
extend self
COLORS = %w[black brown red orange yellow green blue violet grey white].freeze
def value(colors)
first, second = colors[0..1]
[COLORS.index(first), COLORS.index(second)].join.to_i
end
end
| true |
6b41eec095eb6293a815f856b9bda0e1c1eb0257 | Ruby | taoliu12/arrays_and_iteration-lecture | /arrays_and_iteration.rb | UTF-8 | 2,131 | 4.8125 | 5 | [] | no_license | require "pry"
## What is an ARRAY?
# An array is an ordered list of elements (such as: numbers, strings, other arrays, etc)
# Making an Array
my_array = ["hey there", "everyone", "howdy", "neighbor"]
# Accessing an Item in the Array
my_array[0] #=> "hey there"
my_array[1] #=> "everyone"
## What if I want to change ... | true |
8912a5c2d1e2c04ca33d505f3b375686ade1f862 | Ruby | joeyates/imap-backup | /lib/imap/backup/file_mode.rb | UTF-8 | 280 | 2.546875 | 3 | [
"MIT",
"JSON"
] | permissive | module Imap; end
module Imap::Backup
class FileMode
attr_reader :filename
def initialize(filename:)
@filename = filename
end
def mode
return nil if !File.exist?(filename)
stat = File.stat(filename)
stat.mode & 0o777
end
end
end
| true |
8ddf03b5b05959579171444cf9204290d974b071 | Ruby | mlapshin/ruby_revisor_client | /lib/revisor/client/session.rb | UTF-8 | 1,339 | 2.53125 | 3 | [
"MIT"
] | permissive | module Revisor
class Client
class Session
attr_reader :client, :name
def initialize(client, name)
@client = client
@name = name
@tabs = {}
end
def stop
@client.stop_session(self.name)
end
def create_tab(tab_name)
@client.command("sessi... | true |
a40053635b63a61e68ebfe77f20199d2b6a6cc40 | Ruby | millarba/deliberate_practice | /research_method_map.rb | UTF-8 | 772 | 4.28125 | 4 | [] | no_license | a = [ "a", "b", "c", "d" ]
# collect is a synonym for map
p a.map { |x| x + "!" } #=> ["a!", "b!", "c!", "d!"]
# map can be used with index, allows us to track index as well as element
# here x * i is multiplying a string by the index
p a.map.with_index { |x, i| x * i } #=> ["", "b", "cc", "ddd"]
p a ... | true |
526a0caa34bb4a7ab1b9b71792b57f60d00ef30d | Ruby | PhilippePerret/Proximit | /bin/TextAnalyzer/Analyse/TableResultats/Mot/inst/initialize.rb | UTF-8 | 898 | 2.734375 | 3 | [] | no_license | # encoding: UTF-8
=begin
Classe TextAnalyzer::Analyse::TableResultats::Mot
---------------------------------------------------
Instance pour les mots (pour UN mot de résultat)
)
=end
class TextAnalyzer
class Analyse
class TableResultats
class Mot
def initialize imot = nil, data = nil
unless imot.nil? # r... | true |
07ee4dd04b4cecdec119233101302fd2d13122d6 | Ruby | ndo7/online-shop-app | /spec/models/inventory_spec.rb | UTF-8 | 3,778 | 3.015625 | 3 | [] | no_license | # require 'rails_helper'
#
# RSpec.describe Inventory, type: :model do
#
# let(:bman) { User.create(username: "Batman", first_name: "Bruce", last_name: "Wayne", credit_card_number: 101011110000, is_seller: true, email: "bman@wayne_industries.net", password: "not_password") }
#
#
# let(:not_bman) { User.create(usern... | true |
b8ad5292479e618da1804786ef680a0e7dc559a0 | Ruby | sbfaulkner/rsql | /lib/rsql/rsql.rb | UTF-8 | 7,573 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'getoptlong'
require 'readline'
include Readline
require 'shellwords'
include Shellwords
require 'singleton'
module RSQL
OPTIONS = { :mode => 'column', :password => '', :user => ENV['USER'] }
class RSQL < Object
include Singleton
class << self
def execute(command)
# split co... | true |
bb13980f7ce2206fd25868abe907b6e5ef76fb2b | Ruby | bumpouce/ruby-oo-object-relationships-collaborating-objects-lab-seattle-web-030920 | /lib/mp3_importer.rb | UTF-8 | 329 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class MP3Importer
attr_accessor :path
@@all = []
def initialize (path)
@path = path
@@all << self
end
def files
Dir[path + "/*.mp3"].map{ |fullpath| File.basename(fullpath) }
end
def import
files.each {|item| Song.new_by_filename(item)}
... | true |
6f34496ec34bfa04ab6c787ee4448616e94b81df | Ruby | krekoten/SimpleQS | /lib/simple_qs/request/base.rb | UTF-8 | 2,864 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'uri'
require 'net/http'
require 'base64'
require 'hmac-sha1'
module SimpleQS
module Request
class Base
RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
SIGNATURE_VERSION = 2
SIGNATURE_METHOD = 'HmacSHA1'
def initialize(params = {})
self.query_params = param... | true |
5947fa0a90f228fccb4ba085676703e21e6ba8e4 | Ruby | glassjoseph/classroom_exercises | /Week 1/rando_guesser.rb | UTF-8 | 526 | 3.921875 | 4 | [] | no_license |
#set up secret, guess variable, compare
=begin
secret_number = rand(1..10)
puts "(The secret number is #{secret_number})"
guess = gets.chomp
until guess == secret_number
puts "Guess is #{guess}"
puts "Guess again!"
guess = gets.chomp.to_i
end
puts "You guessed it!"
=end
secret_number = rand(1..10)
puts... | true |
c590688f6d24bea67880efceb4db46381baa2af2 | Ruby | sawaezamin/backend_mod_1_prework | /section4/exercises/mycar_launchschool.rb | UTF-8 | 992 | 3.796875 | 4 | [] | no_license | class MyCar
attribute_accessor :color
attribute_view :year
def spray_paint(color)
self.color = color
puts "change the color to #{color}"
end
end
def initialize(year, model, color)
@year = year
@model = model
@color = color
@instant_current_speed = 0
end
def shut_off
@instan... | true |
bb6146f115855bb6981d968f0e821d9c3e081f54 | Ruby | bkleinen/bkleinen.github.io | /bin/hugo_migration/rename_section_header.rb | UTF-8 | 611 | 2.609375 | 3 | [] | no_license | all_index_files = Dir.glob("**/index.md")
all_index_files.each do | index_file_name |
f = File.new(index_file_name)
dir_name = File.dirname(index_file_name)
siblings = Dir.glob(File.join(dir_name,"*.md"))
subdirectories = Dir[File.join(dir_name,"*/")]
children = siblings.size + subdirectories.size
if child... | true |
50e5aa54d8e1e580660dd639fc6fe9d0f4784e42 | Ruby | nicooga/cannabase_test | /lib/game/attack.rb | UTF-8 | 1,272 | 3.6875 | 4 | [] | no_license | # A command object that allows a player to attack another one.
class Game::Attack
# @param game [Game]
# @param player_a [Player]
# @param player_b [Player]
def initialize(game, player_a, player_b)
if (!game.players[player_a.id] || !game.players[player_b.id])
raise 'A player does not belong to this ga... | true |
35e636a10e5e51268d449ee09d81caf80481c74f | Ruby | jainpuja/learnruby | /case_expressions.rb | UTF-8 | 929 | 3.8125 | 4 | [] | no_license | # upcase or downcae
# what def....
def get_day_name(day)
day_name = ""
case day
when "mon"
day_name = "Monday"
when "tue"
day_name = "Tuesday"
when "wed"
day_name = "Wednesday"
when "thu"
day_name = "Thrusday"
when "fri"
day_name = "Friday"
when "... | true |
e96433a0059d530df75b43171331eece78948832 | Ruby | BirukAbreham/AppAcademy | /Ruby/Data Structures/DIY ADT/map.rb | UTF-8 | 1,021 | 4.21875 | 4 | [] | no_license | class Map
def initialize
@map = []
end
def set(key, value)
# either create a new key-value pair or update the
# value for a pre-existing key
if @map.flatten.include?(key)
@map.each_with_index do |pair, idx|
if pair[0] == key
@map[idx] = [key, value]
end
end
... | true |
e77e435dc226662c93ecaabc9d0fb9d637e885d4 | Ruby | ShannonLCapper/zorkda | /lib/zorkda-web/Actions/Utils/equate_with_obj_to_obj_player_has.rb | UTF-8 | 2,556 | 2.9375 | 3 | [] | no_license | module Zorkda
module Actions
module Utils
#DONE
def self.equate_with_obj_to_obj_player_has(player, with_obj, action) #returns nil if no appropriate item found, returns object if item found
if with_obj == "hands" || with_obj == "hand" || with_obj == "fists" || with_obj == "fist"
Zorkda::GameOutput.add... | true |
b37f5cf758421954789778e97ddd4b01ce44dea1 | Ruby | phanhaiquang/table-tennis | /app/models/cup_player.rb | UTF-8 | 1,276 | 2.734375 | 3 | [] | no_license | class CupPlayer < ApplicationRecord
INIT_SCORE = 10
belongs_to :cup
belongs_to :player
def update_player_score
w, l = 0, 0
Match.where(cup: self.cup, player_1: self.player).each do |match|
w += 1 if match.score_1 > match.score_2
l += 1 if match.score_1 < match.score_2
end
Match.whe... | true |
f54272b7bbd87a25ce349ab08a4e686b2e75505a | Ruby | charlenef/tts_ruby | /homework/practice.rb | UTF-8 | 234 | 3.515625 | 4 | [] | no_license | # puts "What is you first name?"
# first_name = gets.chomp
# puts "What is you last name?"
# last_name = gets.chomp
# puts "Hi #{first_name} #{last_name}. Your name is #{first_name.length + last_name.length} characters long."
| true |
d9656e67a40393c322927a28a491f5cd3b9a8199 | Ruby | zhiyuan2007/useful_tools | /ruby/beacon/server/lib/beacon/grid/connection.rb | UTF-8 | 1,018 | 2.765625 | 3 | [] | no_license | require "bunny"
require "forwardable"
module Beacon
class Connection
extend Forwardable
def_delegators :@channel, :topic, :fanout, :direct, :default_exchange, :ack
def_delegators :@connection, :queue_exists?, :exchange_exists?
def initialize(host_name)
@connec... | true |
9d999b1aafb73367998de62eaf3893f6f572610e | Ruby | wachin/Windows-WachiManuales | /Sketchup/Extensiones/Window_Tools/WindowTools1.1/WindowTools1.1/3PointTool.rb | UTF-8 | 5,654 | 2.71875 | 3 | [] | no_license | =begin
# Copyright 2004, @Last Software, Inc.
# The code related to click 3 points was reused here from an original
# example titled rectangle.rb by @Last Software, Inc.
# To it I added the window code.
# Name: 3 Point Rectangle
# Usage: click 3 points, into an EXISTING OPENING, for use with... | true |
cf97b2c2d60ce55d90ac045ee47561ea1793a432 | Ruby | kranthie/garden-rhythms | /ullas/mod_1_intro/assorted.rb | UTF-8 | 2,315 | 3.53125 | 4 | [] | no_license | class Array
def bubble_sort
sorted = self.dup
(sorted.length-1).downto(0) do
|i|
0.upto(i-1) do
|j|
if sorted[j] > sorted[j+1]
sorted[j], sorted[j+1] = sorted[j+1], sorted[j]
end
end
end
sorted
end
def selection_sort
sorted = self.dup
... | true |
fb094880bc242acee0d6d04274c3bfa661a7fd33 | Ruby | scoter-oracle/vagrant | /plugins/provisioners/container/client.rb | UTF-8 | 6,445 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'digest/sha1'
module VagrantPlugins
module ContainerProvisioner
class Client
def initialize(machine, container_command)
@machine = machine
@container_command = container_command
end
# Build an image given a path to a Dockerfile
#
# @param [String] - Path to... | true |
567e86c3a3625a355dd979ce15c2d3cc7110f47f | Ruby | johlym/johnathan-org | /src/resources/wxdata/code/wx_maxes_json.rb | UTF-8 | 316 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'csv'
require 'json'
# read the CSV file into a 2D array
data = CSV.read('3421718_maxes.csv')
# convert the data array to an array of arrays
rows = data.map { |row| row.to_a }
# write the rows array to a JSON file
File.open('3421718_maxes.json', 'w') do |file|
file.write(JSON.pretty_generate(rows))
end | true |
2e5c0a70a31b938639211f3ff23a5333ac8d57ab | Ruby | smolinsg23/lucha-app | /app/helpers/form_inputs_helper.rb | UTF-8 | 4,785 | 2.53125 | 3 | [] | no_license |
module FormInputsHelper
# Helper for Client update and create forms
def education
[
["No High School Diploma", "No High School Diploma"],
["High School Diploma", "High School Diploma"],
["GED", "GED"],
["Vocational Certificate", "Vocational Certificate"],
["Some College/Never Completed", "Some Coll... | true |
487e7695adcf0886fb92b64c167b04ea5b03e2cf | Ruby | virajkulkarni14/Jukutatsu | /lib/DataStructures/sll.rb | UTF-8 | 333 | 2.734375 | 3 | [] | no_license | require_relative 'LinkedListNodeADT'
class DataStructures::SinglyLinkedListADT
LLNode = DataStructures::LinkedListNodeADT.new(:value, :next)
attr_accessor :head
def initialize self
self.head = LLNode.new(nil, nil)
end
def length
end
def appendToTail
end
def insertNode
end
def deleteNod... | true |
24f125d926b433c3e2cfaf0842c3cf2510123fc4 | Ruby | Code-Alliance-Archive/ChartClassifier | /utils.rb | UTF-8 | 112 | 2.625 | 3 | [] | no_license | def is_image?(file)
file.to_s.include?(".gif") or file.to_s.include?(".png") or file.to_s.include?(".jpg")
end | true |
ca901af90f08832d2122ccf0fe52689401712b70 | Ruby | guerilla-di/tracksperanto | /lib/tracksperanto/format_detector.rb | UTF-8 | 1,002 | 3 | 3 | [
"MIT"
] | permissive | # Finds a suitable importer for the chosen file path. Or at least tries to, based on the file extension.
# Will then examine all the importers and ask them if they can handle the specified file
class Tracksperanto::FormatDetector
def initialize(with_path)
perform_detection(with_path)
freeze
end
# Te... | true |
17b982e5b9c885a574f1ebd6c658c5191ac5af0c | Ruby | pathways2050/excel_to_code | /spec/simplify/count_formula_references_spec.rb | UTF-8 | 792 | 2.75 | 3 | [
"MIT"
] | permissive | require_relative '../spec_helper'
describe CountFormulaReferences do
it "should be able to count the number of times a formula is referenced" do
references = {
'sheet1' => {
'A1' => [:cell, "$A$2"],
'A2' => [:cell, "A3"],
'A3' => [:number, 1]
},
'sheet2' => {
'A1' => [:cell, "A2"],
'A2' => [... | true |
e49f15c2c306418b5ada05620e10a9ee302ba85d | Ruby | cfis/tensorflow-ruby | /lib/tensorflow/name_scope.rb | UTF-8 | 1,124 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'set'
module Tensorflow
class NameScope
attr_reader :stack, :names
def initialize
@stack = Array.new
@names = Set.new
end
def name_scope(base_name)
name = self.unique_name(base_name)
stack.push(name)
begin
yield current_scope if block_given?
ensu... | true |
c615c64e40644e41eb668d72aa2b98b9ac3cd002 | Ruby | servsecCrucible/hw_3-credit_card_crypto | /aes_cipher.rb | UTF-8 | 1,013 | 3.203125 | 3 | [] | no_license | ## AesCipher
require 'openssl'
require 'base64'
require 'json'
require 'digest/sha1'
## AesCipher
module AesCipher
def self.encrypt(document, key)
# TODO: Return JSON string of array: [iv, ciphertext]
# where iv is the random intialization vector used in AES
# and ciphertext is the output of ... | true |
330dd2fc8a1065a8b0271b0fe4c7ca9791b16f3d | Ruby | FrankYadon/AppAcademyOpen | /week0/hotel_project/lib/hotel.rb | UTF-8 | 808 | 3.625 | 4 | [] | no_license | require_relative "room"
class Hotel
def initialize(name, room_hash)
@name = name
@rooms = {}
room_hash.each { |k, v| @rooms[k] = Room.new(v) }
end
def name
@name.split.map(&:capitalize).join(" ")
end
def rooms
@rooms
end
def room_exists?(room)
@rooms.keys.include?(room)
end... | true |
d4c54b2f4b532b653c60d41ca7d3f06e16db185c | Ruby | PhilippePerret/WriterToolbox | /objet/quiz/new.rb | UTF-8 | 1,113 | 2.71875 | 3 | [] | no_license | # encoding: UTF-8
# Seulement pour un administrateur
raise_unless_admin
class Quiz
class << self
# Méthode qui crée la nouvelle base de données de quiz
def create_new_database
@db_name = param(:new_base_test_name).nil_if_empty
check_value_new_database || return
# === CRÉATION DE LA BASE =... | true |
94d2f0be335dbdf305ae0cb6fa0623e0a0f4fc0f | Ruby | stanleysx/w3d1 | /animals.rb | UTF-8 | 353 | 4.59375 | 5 | [] | no_license | print "Enter an animal: "
animal = gets.chomp
puts "The animal is #{animal}"
if animal.downcase == "dog" # Note use == to compare values. = is asigning variables.
puts "woof"
elsif animal.downcase == "cow"
puts "moo"
elsif animal.downcase == "cat"
puts "meow"
else # runs if no other if conditions are true
puts... | true |
b82687183e2e479e632c0dee9cda226df1484f0d | Ruby | onerobotics/tp_plus | /lib/tp_plus/nodes/for_node.rb | UTF-8 | 665 | 2.78125 | 3 | [
"MIT"
] | permissive | module TPPlus
module Nodes
class ForNode < BaseNode
def initialize(var_node, initial_value_node, final_value_node, block)
@var_node = var_node
@initial_value_node = initial_value_node
@final_value_node = final_value_node
@block = block.flatten.reject ... | true |
5a43b2aadc12e148324f978a00da09995a7725d5 | Ruby | 16sheep/oop-practice | /app/models/character.rb | UTF-8 | 387 | 3.1875 | 3 | [] | no_license | class Character
# belongs to movie
# belongs to show
# belongs to actor
attr_accessor :name, :actor, :movie, :show
ALL = []
def initialize(name)
@name = name
ALL << self
end
def self.all
ALL
end
def self.most_apperances
grouped_characters = ALL.group_by{|character| character.n... | true |
5d142a9cc7e42def10035c761f4b00f9e8ed8ffb | Ruby | sundayspecial/ita | /hw24/lib/script24_01.rb | UTF-8 | 711 | 3.015625 | 3 | [] | no_license | # ========================================================================
# Script = script24_01.rb
# ========================================================================
# Description = "This script outputs plural form from the JSON file"
# Name = "Kristina Rudzinskaya"
# Email = "kristina.rudzinskaya@gma... | true |
9a147fb593806b59a14a1bf2e01475bdc1cbe41a | Ruby | YashUppal/appAcademy | /Intro to Programming/Conditionals/larger_number.rb | UTF-8 | 284 | 4.9375 | 5 | [] | no_license | # Write a method larger_number(num1, num2) that takes in two numbers and returns the larger of the two numbers.
def larger_number(num1, num2)
if num1 > num2
return num1
else
return num2
end
end
puts larger_number(42, 28) # => 42
puts larger_number(99, 100) # => 100 | true |
a600db30b32df7c5c17dba6895eefe53cb0bcf48 | Ruby | abetty1218/hotel_app | /app/models/favorite.rb | UTF-8 | 372 | 2.59375 | 3 | [] | no_license | class Favorite < ApplicationRecord
belongs_to :user
validates :name, presence: true
validates :memo, presence: true
validate :memo_length
def memo_length
memo_for_validation = memo.gsub(/\r\n/,"").gsub(/r/,"").gsub(/\s/,"")
if memo_for_validation.length > 250
errors.add(:memo, "は250文字以内で入力してく... | true |
f013c4520bbeec293ca540f5887a7e4910acf0f9 | Ruby | basman/Sea-Defender | /utils/svg_to_m.rb | UTF-8 | 1,681 | 2.921875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# converts SVG paths to .m
#
# .m format is equivalent to SVG path element, with no whitespace, commands 'a-zA-Z' unchanged,
# and each number normalized into 0.0-1.0 range and converted into unsigned short (0-65535)
require 'rexml/document'
include REXML
require 'vector.rb'
#ARGV = ["../data/m... | true |
7700354d6a2fcdcc5f158897bc7fab51f65c4914 | Ruby | learn-academy-2019-charlie/ruby-assessment-lali20021 | /ruby.rb | UTF-8 | 1,943 | 4.90625 | 5 | [] | no_license | # Ruby Assessments
#### 1. Use two different Ruby loops to loop over this array, multiplying each element by 2.
tempArray = [1, 2, 6, 9, 3, 21]
tempArray = [1, 2, 6, 9, 3, 21]
tempArray.each do |a|
puts a*2
end
puts tempArray.map { |a| a * 2}
#### 2. From all the built in Ruby methods we've seen in class this... | true |
ae61e2b8c146ab11b13bdbf7a06035fad72380d2 | Ruby | IanMadlenya/Portfolio-Manager | /lib/core_ext/fixnum.rb | UTF-8 | 149 | 2.765625 | 3 | [] | no_license | class Fixnum
def as_currency
((self * 100).round)/100.0
end
end
class Float
def as_currency
((self * 100).round)/100.0
end
end | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.