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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4e80614fb3c56f3b270c2f487d0673181bddf2c2 | Ruby | croby/flexmls_api | /lib/flexmls_api/response.rb | UTF-8 | 2,026 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | module FlexmlsApi
# API Response interface
module Response
ATTRIBUTES = [:code, :message, :results, :success, :pagination, :details]
attr_accessor *ATTRIBUTES
def success?
@success
end
end
# All known response codes listed in the API
module ResponseCodes
NOT_FOUND = 404
METHOD... | true |
2f29535434064ec302679a25624f6dc80a6c9f17 | Ruby | foobert/gc | /app/test/cachecache/timeParser.rb | UTF-8 | 1,044 | 2.625 | 3 | [
"MIT"
] | permissive | require 'cachecache/timeParser'
require 'minitest/autorun'
describe CacheCache::TimeParser do
before do
@tp = CacheCache::TimeParser.new
end
describe 'parse' do
it 'should parse dates without timezone information' do
parsed = @tp.parse('/Date(1198908717056)/')
parse... | true |
5a351952fb3ef2f25e7bf7a98e32e173ba83f3dd | Ruby | zanhe/sea-sfo-060120-mod1-final-project | /db/seeds.rb | UTF-8 | 6,241 | 2.546875 | 3 | [] | no_license | Customer.destroy_all
CustomerList.destroy_all
WineClub.destroy_all
WineList.destroy_all
Wine.destroy_all
#customer
danira = Customer.create(name: "Danira", age: 31)
zana = Customer.create(name: "Zana", age: 22, wine_preference: "white")
gabriel = Customer.create(name: "Gabriel", age: 30, wine_preference: "red")
bran... | true |
dfc2ff4ebdf5c3151793211478edf209153823c2 | Ruby | cielavenir/procon | /atcoder/tyama_atcoderyahooprocon2017qualC.rb | UTF-8 | 374 | 2.78125 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
n,k=gets.split.map &:to_i
a=gets.split.map &:to_i
s=n.times.map{gets.chomp}
t=[]
#aがソートされてないなんて聞いてないよ(sample is crappy!) ToT
a.sort_by(&:-@).each{|i|t<<s.delete_at(i-1)}
r=t[0]
t.map{|e|l=[e.size,r.size].min;r=r[0,(0...l).find{|i|e[i]!=r[i]}||l]}
t=(0..r.size).find{|i|s.none?{|e|e.start_with?(r[0,i])}}
... | true |
3882e806d409aa5ff376b10084a6e9cbe69fa604 | Ruby | katemyer/interview_practice | /smallest_range.rb | UTF-8 | 1,009 | 3.6875 | 4 | [] | no_license | # @param {Integer[]} a
# @param {Integer} k
# @return {Integer}
def smallest_range_i(a, k)
#positive values in array
#2- values for now
#return nil if x is out of range of -k..k
a = [2,5]
#k = 3
#pick number between -3 < x =1 <3
#B = [3, 6]
#output: 3
#loop through array_a
a.each do |num|
#... | true |
de670d510138b945b424cf71e6505deca3619346 | Ruby | bitfede/IronHack-webDev | /ironHackPreW/rubycode/fizzbuzz/fizzbuzz.rb | UTF-8 | 296 | 3.546875 | 4 | [] | no_license | num = 1
while num <= 100
result = ""
str = num.to_s
if (num % 3 == 0)
result = result + "Fizz"
end
if (num % 5 == 0)
result = result + "Buzz"
end
if (str[0] == '1')
result = result + "Bang"
end
if (result == "")
result = str
end
puts result
num = num + 1
end
| true |
44f79e8cbe2ecab2f90a758f98c813cba35451d6 | Ruby | thebigw4lrus/MissionToMars | /position.rb | UTF-8 | 462 | 3.59375 | 4 | [] | no_license | =begin
* Name: Position
* Description: This class represents the exact position of the rover over the plateau
* Input: Position.new(x, y)
* Author: Javier A. Contreras V.
* Date: MAr 19, 2015
=end
class Position
attr_accessor :x, :y
def initialize(position)
if position.respond_to? :split
p... | true |
1a4a006d64806cd0eee6ed20dfe066a37f4bf038 | Ruby | sul-dlss-deprecated/revs | /lib/activesolr_helper.rb | UTF-8 | 15,010 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | # These methods are mixed into the SolrDocument model and provide ActiveRecord like finder by ID, dynamic setters and getters based on field configuration, and the ability to cache edits, update the solr document and more
module ActivesolrHelper
attr_reader :errors
module ClassMethods
# This is provided by ... | true |
27bb104573950f8d930609fa5bebb0dcb7492f3a | Ruby | castwide/solargraph | /lib/solargraph/diagnostics/type_check.rb | UTF-8 | 1,830 | 2.546875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Solargraph
module Diagnostics
# TypeCheck reports methods with undefined return types, untagged
# parameters, and invalid param tags.
#
class TypeCheck < Base
def diagnose source, api_map
# return [] unless args.include?('always') || api_map.workspac... | true |
f533dcf7a800b2ee7f6966f1c7dc298abf7cbb1c | Ruby | michael-dollosa/ruby-coding-practice | /index_of_alphabet/index_of_alphabet_spec.rb | UTF-8 | 442 | 2.890625 | 3 | [] | no_license | require_relative './index_of_alphabet.rb'
describe 'Index of Alphabet' do
it "should return A" do expect(index_of_alphabet(1)).to eq("A") end
it "should return T" do expect(index_of_alphabet(20)).to eq("T") end
it "should return ALL" do expect(index_of_alphabet(1000)).to eq("ALL") end
it "should return Z" do e... | true |
5a921bf20b801403a9409340f3b9f0dde2178fad | Ruby | bstiber/launch_school_exercises | /small_problems/easy7/test.rb | UTF-8 | 363 | 3.375 | 3 | [] | no_license | def find_middle_word(sentence)
words = sentence.split(" ")
return words[0] if words.count == 1
return "" if words.empty?
return "No middle word" if words.count.even?
midpoint = (words.count / 2).round
words[midpoint]
end
p find_middle_word('last word')
p find_middle_word('Launch School is great!')
p find_... | true |
17df4460e8112396386f062c32c69382c45b944f | Ruby | efraimmgon/project_dom_tree | /lib/node_renderer.rb | UTF-8 | 434 | 3.28125 | 3 | [] | no_license | class NodeRenderer
attr_accessor :tree
def initialize(tr)
@tree = tr
end
# How many total nodes there are in the sub-tree below this node
def render(node = nil)
elt = node | tree
puts "\nNodes: #{elt.body.count}"
puts "\nAttributes:"
elt.attrs.each{ |k, v| puts("#{k}: #{v}") }
child... | true |
98237b3b1a7961241e85314ffd1e9306baadb487 | Ruby | Kylemiller995/PDA | /week_02/hash.rb | UTF-8 | 360 | 2.734375 | 3 | [] | no_license | favourite_movie = [
{
director: "pedro jackson",
run_time_minutes: 215,
title: "lotr"
},
{
director: "",
run_time_minutes: 215,
title: ""
},
{
director: "pedro jackson",
run_time_minutes: 215,
title: "lotr"
},
]
def return_director(favourite_movie)
puts favourite_movi... | true |
c77cf3d619711ff337b70fe2148385f6123665f4 | Ruby | tenderlove/concurrent-ruby | /lib/concurrent/lazy_register.rb | UTF-8 | 1,628 | 3.15625 | 3 | [
"Ruby",
"MIT"
] | permissive | require 'concurrent/atomic'
require 'concurrent/delay'
module Concurrent
# Allows to store lazy evaluated values under keys. Uses `Delay`s.
# @example
# register = Concurrent::LazyRegister.new
# #=> #<Concurrent::LazyRegister:0x007fd7ecd5e230 @data=#<Concurrent::Atomic:0x007fd7ecd5e1e0>>
# regis... | true |
d1ca607f74d5e6f0b77e69c7f8ea933ad7134237 | Ruby | renuo/redmine_auto_time_entries | /spec/splitter_spec.rb | UTF-8 | 6,063 | 2.515625 | 3 | [
"MIT"
] | permissive | require_relative 'spec_helper'
require_relative 'redmine_adapter_mock'
require 'date'
describe 'Splitter' do
before(:each) do
@redmine_adapter_mock = RedmineAdapterMock.new
@splitter = Splitter.new(@redmine_adapter_mock)
@tm = RedmineAdapterMock::TimeEntryMock
end
it 'should not assign invalid entri... | true |
0b67ac6001124f9aa9804e6dd7891ac5cdc181a6 | Ruby | OwNet/qtownet | /IntegrationTests/spec/support/database_helpers.rb | UTF-8 | 1,406 | 2.90625 | 3 | [
"MIT"
] | permissive | module DatabaseHelpers
##
#
# Number of rows in table *entity*.
#
def count_of(entity)
execute_with_retry("SELECT COUNT(*) FROM #{entity};").first[0]
end
##
#
# Select all rows from *table*. Options are *where*, *order* and *limit*. Values are inserted directly into query.
#
def select_from(table, options... | true |
3d492fb5adb550c499e272518e688a63cf5e5c1e | Ruby | mx98829/123 | /Lesson_4/test107.rb | UTF-8 | 420 | 4.75 | 5 | [] | no_license | # Ruby and Javascript lets you re-open classes so you can add new functionality to existing classes and objects.
# In this kata, you'll have to add a new method in the String class that calls the upcase method (toUpperCase() in Javascript), so that:
# Ruby
# "abc".my_new_method
# JS
# "abc".myNewMethod();
# returns... | true |
7d45317513ddda4ca4e30110d2c5c4b62353ca8e | Ruby | areejeweida/opentable | /lib/open_table/parser.rb | UTF-8 | 1,238 | 2.890625 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
require "csv"
module OpenTable
class Parser
# Initialize a new snapshot instance
# @param path [String] path to OpenTable xls spreadsheet
def initialize(path)
@path = path
end
# Parses rows and returns an array with formatted hashes
# @return [Array<Hash>]
def par... | true |
4e19d2bb80d89daf0f32f1d119a0071688415b8a | Ruby | PCervone/intro_to_ruby | /5_Loops_And_Iterators/ex2.rb | UTF-8 | 137 | 3.453125 | 3 | [
"MIT"
] | permissive | loop do
print "Write \"STOP\" to stop the program: "
phrase = gets.chomp.upcase
phrase == "STOP" ? break : puts("Next cycle..")
end | true |
acfd438b8a72c22867dafb020bb9ca54b6b0ae26 | Ruby | cbrulak/Is-X-Jelly-Y | /app/controllers/application_controller.rb | UTF-8 | 1,000 | 2.640625 | 3 | [] | no_license | # We take the date from the hostname, strip things down,
# and compare it to today's day
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_timezone
def set_timezone
Time.zone = 'Mountain Time (US & Canada)'
end
def get_host
request.host == "localhost" ? "S... | true |
178178257cfd8ec86255903396576d5d02630e3f | Ruby | SugiKent/lesson_show_test | /app.rb | UTF-8 | 960 | 2.609375 | 3 | [] | no_license | require 'mechanize'
require 'pry'
require 'csv'
agent = Mechanize.new
agent.user_agent_alias = "Mac Safari 4"
base_url = "http://0.0.0.0:3000/"
time_stamp = Time.now.strftime("%H%M%S")
#for id in 13650..21663 do
ids = [13702,
16760,
16761,
16762,
16763,
16764,
20082,
20429,
20430,
20431,
20616,
20816,]
ids.each do |i... | true |
277356f338731bd10f0c78996486f52172bf69ee | Ruby | linsujie/bibcmd | /menu.rb | UTF-8 | 5,186 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
require_relative 'frame.rb'
require_relative 'foldlist.rb'
# The basic utils for menu
module MenuUtils
attr_reader :curse, :scurse, :list
public
def setctrl(qkey, dkey, ukey)
@qkey = qkey
@dkey = dkey
@ukey = ukey
end
def set(curse, scurse, list = @list)
... | true |
b86ae7ca6bd7cd7bc848c8b83cf347e58d854131 | Ruby | envp/pudding | /lib/app/browser.rb | UTF-8 | 2,715 | 2.65625 | 3 | [] | no_license | require 'mechanize'
require_relative 'config.rb'
require_relative 'downloader.rb'
require_relative 'helpers/greeting_helpers.rb'
module Browser
include Downloader
include Configuration
include Greeting
class Brobot < Mechanize::HTTP::Agent
attr_reader :agent, :unread_notification_count
# Browser-bot... | true |
5fbb51d2fc294312e8798ab115781873bf0e0b1b | Ruby | k-matida/SandBox | /Ruby-YAML/example07.rb | UTF-8 | 638 | 3.109375 | 3 | [] | no_license | # YAML TEXT
str = <<END
langs:
- name: Ruby
url: http://www.ruby-lang.org
- name: Python
url: http://www.python.org
- name: PHP
url: http://www.php.net
END
## after parse, it make tree
require 'yaml'
tree = YAML.parse(str) # tree => YAML::Syck::Node object
p tree.methods
## search for YPath
path_list ... | true |
aade502e5e778feadeb316a69a8c623e0dc4ffba | Ruby | noahmilstein/news-aggregator | /server.rb | UTF-8 | 748 | 2.671875 | 3 | [] | no_license | require 'sinatra'
require 'csv'
get "/" do
"<h1>News Aggregator</h1>"
redirect "/articles"
end
get "/articles" do
@file = File.readlines("articles.csv")
erb :articles
end
post "/articles/new" do
@title = params[:title]
@url = params[:url]
@description = params[:description]
@error = nil
if @title... | true |
99a9d38db72cf8cbb8b04839b0f704868f173266 | Ruby | derekorgan/ruby | /Terrain/tc_twodarray.rb | UTF-8 | 1,921 | 3.640625 | 4 | [] | no_license | require 'test/unit'
require './twodarray.rb'
class TC_TwoDArray < Test::Unit::TestCase
def setup
@x = [1,2,3]
@y = [4,5,6]
@z = [7,8,9]
@a = TwoDArray.new(3,3)
@b = TwoDArray.new
end
def test_setter_getter
@x.each_index do |i|
@a[i,0] = @x[i]
end
assert_equal(1, @a[0,0], "First value should b... | true |
3cb230be6c395df0002bd3812a2926dadf6b4f47 | Ruby | saisai/ruby | /labs/subway_helper.rb | UTF-8 | 964 | 3.84375 | 4 | [] | no_license | require 'pry'
n_stops = %w{times\ square 34th 28th 23rd union\ square}
l_stops = %w{8th 6th union\ square 3rd 1st }
six_stops = %w{grand\ central 33rd 28th 23rd union\ square}
puts "Which subway are you taking? (N), (L), (6) or (Q)uit"
train = gets.chomp.upcase
while train != "Q"
puts "What's your starting Station... | true |
7f335b5ac4808c23234d9cdf922ab536ccfc53d3 | Ruby | nitinsavant/algorithms_exercises | /dynamic_programming/word_break.rb | UTF-8 | 1,169 | 4.1875 | 4 | [] | no_license | # Mental Model
# - Use backtracking to build a set of subtrings. The dead-end condition is if the current substring is not in the dictionary. But it's very slow. It's O(n^2) time complexity.
# - Instead, since we don't need to save all the subtrings, we just need to return a boolean, DP is worth a shot. Need to break t... | true |
b5709cc626360acc931d9c0faa0c502889a7ebd0 | Ruby | snrkiwi/utilrb | /test/test_weakref.rb | UTF-8 | 2,267 | 2.59375 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'test/unit/testcase'
require 'utilrb/weakref'
Utilrb.require_ext('TC_WeakRef') do
class TC_WeakRef < Test::Unit::TestCase
WeakRef = Utilrb::WeakRef
def test_normal
obj = Object.new
ref = Utilrb::WeakRef.new(obj)
assert_equal(obj, ref.get)
end
... | true |
b315354a1b4f348ae18d560c0a4541b9fdfb60ba | Ruby | HealthyMeRPG/healthymerpg-api | /db/seeds.rb | UTF-8 | 1,556 | 2.53125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
8290037edb65c3a9f7fdbd2f49a6492b69f9ea20 | Ruby | nelstrom/StenoBricks | /bin/steno-bricks | UTF-8 | 1,164 | 2.546875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'thor'
require_relative '../lib/steno'
require_relative '../lib/brick_mapper'
require 'json'
class StenoBricks < Thor
desc "sort --filepath definitions.json", "Sort the specified .json file containing definitions"
option :filepath, default: 'data/definitions.json'
def sort
defini... | true |
e4daf71866a675bdf2e266dc102da0c2c5ac31dc | Ruby | trisulnsm/trisul-scripts | /trp/getpcap/getpackets.rb | UTF-8 | 1,840 | 2.765625 | 3 | [] | no_license | # Trisul Remote Protocol TRP Demo script
#
#
# Save all packets in timeframe to a PCAP file
#
#
require 'trisulrp'
USAGE = "Usage: getpackets.rb ZMQ_ENDPOINT \n" \
"Example: 1) ruby getpackets.rb ipc:///usr/local/var/lib/trisul/CONTEXT0/run/trp_0\n"\
" 2) ruby getpackets.rb tcp://localhost... | true |
bbfacb0140648c7c172a5eaebd52e2e29d2a96f9 | Ruby | ChristianCarey/learn_ruby | /01_temperature/temperature.rb | UTF-8 | 94 | 3.0625 | 3 | [] | no_license | def ftoc(f_temp)
(f_temp - 32) / (9.0/5.0)
end
def ctof(c_temp)
c_temp * (9.0/5.0) + 32
end | true |
56d84444892fc5edb66e802bbd5666715a17d1a5 | Ruby | selfup/enigma | /lib/output.rb | UTF-8 | 264 | 2.578125 | 3 | [
"MIT"
] | permissive | require_relative "offset"
class Output
def date_for_output
Offset.new.date_gen
end
def terminal_output(keykey)
"Created #{ARGV[1]} with the key #{keykey} and the date #{date_for_output}"
end
def crack_output
"Created #{ARGV[1]}"
end
end
| true |
5336e032b217c3403a450b005ca78e75b6a05abf | Ruby | allisonkadel/sql-library-lab-v-000 | /lib/querying.rb | UTF-8 | 1,348 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
"SELECT books.title, books.year FROM books
WHERE series_id = 1
ORDER BY books.year"
end
def select_name_and_motto_of_char_with_longest_motto
"SELECT characters.name, characters.motto FROM characters
ORDER BY LENGTH(characters.motto) DESC LIMIT 1"
end
... | true |
5f7c22bfac5c88ec5c7f20ea0f117aba98125385 | Ruby | weimingtom/ruser | /menu.rb | UTF-8 | 1,225 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'gosu'
class Menu < Gosu::TextInput
INACTIVE_COLOR = 0xcc666666
ACTIVE_COLOR = 0xccff6666
SELECTION_COLOR = 0xcc0000ff
CARET_COLOR = 0xffffffff
PADDING = 5
attr_reader :height, :width, :x,:y
def initialize(window, font, title,height=40,width=40)
# TextInput's constructor doesn't exp... | true |
5f006a7ba5d2c62c8fd9e95ffc4a5771865794a2 | Ruby | smartweber/ror-getmeed | /OfflineScripts/ExternalDataScrappers/ScrapeUWDirectory.rb | UTF-8 | 4,459 | 2.546875 | 3 | [] | no_license | # Takes input the names of the students in a tsv file
# Search in UW student directory the names of the students matching every word of name of the student
# in tsv file to have max matching students.
# Finally outputs the detailed data of the student and these can be duplicates.
require './OfflineScripts/lib/utils.rb... | true |
44403bf552e22d30df42c0a246847358df6e0685 | Ruby | bmiller42/Web-development-project | /img/app/models/image.rb | UTF-8 | 814 | 2.53125 | 3 | [] | no_license | class Image < ActiveRecord::Base
belongs_to :user
has_many :users, through: :image_users
has_many :tags
has_many :image_users
def is_eligible
user_array = User.all - self.users - [self.user]
user_array = user_array.map {|user| [user.name + "("+ user.email + ")", user.id]}
end
... | true |
db70e0bb48a8d613c689a726fb0f2a8509bfb294 | Ruby | onurkucukkece/format_parser | /spec/io_utils_spec.rb | UTF-8 | 1,159 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe 'IOUtils' do
let(:io) { File.open(fixtures_dir + '/test.jpg', 'rb') }
include FormatParser::IOUtils
describe '#safe_read' do
it 'raises if the requested bytes are past the EOF' do
io.seek(268118) # Seek to the actual end of the file
expect {
safe_read(io, 1... | true |
a2634464987c6d2612a32ea6f6377933b741546c | Ruby | paninapress/Exercises-WDI-Week2 | /sorted_array.rb | UTF-8 | 1,119 | 3.859375 | 4 | [] | no_license | class SortedArray
attr_accessor :internal_arr # This is for convenience in the tests.
def initialize(input_arr=[])
@internal_arr = []
# Fill in the rest of the initialize method here.
# What should you do with each element of the incoming array?
input_arr.each { |x|
add(x)
}
end
def ... | true |
64e59256647d5935d34e627c81f9ee643661db7f | Ruby | pbomba/Dungeon_Time | /run.rb | UTF-8 | 2,191 | 2.796875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative 'config/environment'
ActiveRecord::Base.logger = nil # comment out if want to see SQL logs
system('clear')
pid = fork{ exec 'afplay', "media/Far-Away-Places-Call.mp3"}
# sleep(132)
current_character = Game.welcome
current_game = Game.new_game(current_character)
current_game.weapon_choice
current... | true |
133f79de4f91baa03ec8323fb5c16ac7410a74b3 | Ruby | kbrock/bin | /autospork.rb | UTF-8 | 2,899 | 2.625 | 3 | [] | no_license | #!/usr/bin/env watchr
#RUN_ALL_TESTS||=true
unless defined?(GROWL)
ENV["WATCHR"] = "1"
GROWL=`which growlnotify`.chomp
IMAGE_DIR=File.expand_path("~/.watchr_images/")
#SPORK=true
end
def growl(message,title=nil,image=nil)
title ||= "Watchr Test Results"
message.gsub! /\[[0-9]+?m/, ''
image =
if imag... | true |
dfeaec94beff3c0b7fc165b801142e0113e275cd | Ruby | doloreszhang/lolitado | /lib/lolitado/api.rb | UTF-8 | 4,080 | 2.859375 | 3 | [] | no_license | require 'httparty'
module Lolitado
class API
include HTTParty
#
# format api response
#
# @param response [String] api response
# @param msecs [Float] benchmark for api response time
#
def self.format_response response, msecs
new_response = {:response => response, :message => re... | true |
c767af02b95f0269428b55294deed8cd871228ff | Ruby | Archeo3DProd/bucket_list | /test/models/comment_test.rb | UTF-8 | 1,271 | 2.59375 | 3 | [] | no_license | require 'test_helper'
class CommentTest < ActiveSupport::TestCase
test 'changing the associated Idea for a Comment' do
first_idea = Idea.new
first_idea.title = 'Changing the associated Idea for a Comment'
first_idea.save!
comment = Comment.new(body: "I'd like to do this!", idea: first_idea, user: Us... | true |
f7975807a66611bbd2359c5fe7fe186cda40988f | Ruby | adamsanderson/metric_adapter | /lib/location.rb | UTF-8 | 661 | 2.921875 | 3 | [] | no_license | module MetricAdapter
class Location
attr_reader :path, :line
def initialize(combined_path, line = 0)
@path, @line = parse_path(combined_path || '')
@line ||= line
end
def to_s
"#{path}:#{line}"
end
def <=>(other)
[path,line] <=> [other.path, other.line]
... | true |
ef129db4f0d650027697a276ca3f539230f3434c | Ruby | alu0101371573/lpp-prct | /lib/prct06/bundler.rb | UTF-8 | 15,498 | 3.609375 | 4 | [] | no_license | require "prct06/bundler/version"
module Prct06
module Bundler
class Error < StandardError; end
##
# Class that rapresents an Aliment which is described by a name,
# the grams of co2 emitted per kg of produced Aliment,
# the m^2 per year used in order to produce it,
# and then we have the energy in... | true |
3e38822b533e56da471d018000665ecd23a1a36a | Ruby | micealgallagher/plezi-website | /app/ai_visitors.rb | UTF-8 | 1,731 | 2.703125 | 3 | [] | no_license | class AIConnection
NAMES = %w(Finley Kadence Paityn Zander Theresa Lilyana Lewis Waylon Samuel Haiden Saniya Kyson Corinne Neil Maia Gia Lyla Kendrick Aditya Seamus
Roselyn Ashleigh Hailey Edgar Caio Luis Gustavo Emil Jean Joey Anais Margaret).freeze
MESSAGES = [
'Hi!',
'hi :-)',
'hi',
... | true |
1388e60ee435486e25590829b3df833df4c33dd7 | Ruby | TimRobinson1/messing-with-ruby | /codewars-experiments/length-test.rb | UTF-8 | 505 | 4.03125 | 4 | [] | no_license | # Testing for names of four letters in length. Learn Ruby the Hard Way says that there should be an else section to the if statement.
friends = ["Ryan", "Kieran", "Alexander", "123", "1234"]
x = 0
true_friends = []
until x == friends.length do
if friends[x].length == 4
true_friends.push(friends[x])
x += 1
... | true |
694cf6bc70bdbda43209ef6dded55c0efeeeba80 | Ruby | notmarkmiranda/ruby-exercises | /objects-and-methods/exercise-2/lib/bag.rb | UTF-8 | 493 | 3.578125 | 4 | [
"MIT"
] | permissive |
class Bag
attr_reader :bag, :candy, :type
def initialize
@candies = []
@taken = []
end
def empty?
@candies.empty?
end
def count
@candies.count
end
def candies
@candies
end
def << (candy)
@candies << candy
end
def contains?(candy_type)
@candies.find { |candy| ca... | true |
19b42f759c2c6daa725b92e8907a8c1d0f201261 | Ruby | lbadura/skypark | /lib/parking_report_row.rb | UTF-8 | 517 | 2.9375 | 3 | [] | no_license | class ParkingReportRow
def initialize(owner, department)
@owner = owner
@department = department
@usage = []
end
def add_record(record)
@usage << record
end
def total
usage.map {|u| u.gross_fee}.sum.round(2)
end
def license_costs
usage.select {|u| u.class.to_s == "LicenseRecord"... | true |
fa96fafc86460d28a02788c48a1b71368fa4e435 | Ruby | mhennemeyer/macspec | /lib/mac_spec/matcher_system/built_in/change_expectations.rb | UTF-8 | 1,796 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module MacSpec
module MatcherSystem
module Expectations
module TestCaseExtensions
# Checks if the given block alters the value of the block attached to change
#
# ==== Examples
# lambda {var += 1}.should change {var}.by(1)
# lambda {var += 2}.should change {var}.b... | true |
19701a7cbef4e63441cf3a20541174bdc99d7067 | Ruby | Scrimmage/gem_activerecord_hoarder | /lib/activerecord_hoarder/storages.rb | UTF-8 | 543 | 2.796875 | 3 | [
"MIT"
] | permissive | module ::ActiverecordHoarder
class Storages
STORAGE_DICT = {
aws_s3: ::ActiverecordHoarder::AwsS3
}
def self.check_storage(storage_key)
raise ::ActiverecordHoarder::StorageError.new("unknown storage (#{storage_key}), known keys are #{STORAGE_DICT.keys}") if !is_valid_storage?(storage_key)
... | true |
7348cf3420bda0e043768618779040c6efbc0693 | Ruby | Su7ech/Pre_Course | /Hashes/exercise4.rb | UTF-8 | 128 | 2.859375 | 3 | [] | no_license | person = { name: 'Bob', occupation: 'web developer', hobbies: 'painting' }
# Express the name of the person
puts person[:name] | true |
c5c71f458b3a0591847c98f5fc2bb42325808929 | Ruby | kentor/euler_ruby | /041.rb | UTF-8 | 319 | 3.515625 | 4 | [] | no_license | class Integer
def prime?
return false if self % 2 == 0
return false if (self + 1) % 6 != 0 && (self - 1) % 6 != 0
3.step(Math.sqrt(self).floor, 2) do |div|
return false if self % div == 0
end
return true
end
end
puts (1..7).to_a.permutation.map { |a| a.join.to_i }.select(&:prime?).max
| true |
a6d340169ef3fbb9a4fa25693ae70d15f16a559c | Ruby | sunny-b/Ruby_Practice | /minilang.rb | UTF-8 | 1,046 | 3.671875 | 4 | [] | no_license | require 'pry'
OPTIONS = %w(add sub mult div mod pop)
def minilang(input)
register = 0
stack = []
input_commands = input.downcase.split(' ')
interpret_command(input_commands, register, stack)
end
def interpret_command(input_commands, register, stack)
input_commands.map do |command|
manipulate = false... | true |
f8b5bf6a896bafb8ef53f2d391377466a12c61df | Ruby | kantoliinary/kantoliina | /app/controllers/statistics_controller.rb | UTF-8 | 2,380 | 2.65625 | 3 | [] | no_license | #encoding: utf-8
##
# The controller for the statistics page
class StatisticsController < ApplicationController
##
# Initializes the statistics variables, calls the counting method and renders the statistics page
def index
@members = Member.includes(:membergroup)
@active = 0
@deleted = 0
@tota... | true |
6da19704c1d0fe77d40071ffb55c607b16955bd4 | Ruby | narath/OpenCellPager | /test/unit/user_test.rb | UTF-8 | 6,038 | 2.625 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/../test_helper'
module TestHelper
# returns the created msg
def simple_create_msg(org, from, to, text)
m = Msg.new(:from=>from, :text=>text)
m.org = org
m.recipient = to
m.save!
p = Page.new()
p.org = org
p.msg = m
p.user = to
p.save!
ret... | true |
987c67de33d6e1649fbafb39db0cd148803050c0 | Ruby | owenchen93/github-mirror | /fixes/update_deleted.rb | UTF-8 | 3,319 | 2.578125 | 3 | [
"BSD-3-Clause",
"BSD-2-Clause"
] | permissive | #!/usr/bin/env ruby
require 'ghtorrent'
class GHTFixDeleted < GHTorrent::Command
include GHTorrent::Settings
include GHTorrent::Retriever
include GHTorrent::Persister
def prepare_options(options)
options.banner <<-BANNER
Updates the deleted field in the project table with current data
#{command_name} o... | true |
674a95925e537ef69911a09a6b86ce2a9f48d951 | Ruby | quipper/mix_tape | /lib/mix_tape/fake_tracker.rb | UTF-8 | 645 | 2.59375 | 3 | [
"MIT"
] | permissive | module MixTape
class FakeTracker
attr_reader :console_logging
def initialize(console_logging)
@console_logging = console_logging
end
def track(distinct_id, name, args={})
puts "FakeTracker.track #{distinct_id}, #{name}, #{args}" if console_logging
end
def people
@people |... | true |
1adcaef30459400a7d469cbbdf6f2d81dae436b8 | Ruby | yakreved/RubyRNN | /spec/test.rb | UTF-8 | 980 | 3.109375 | 3 | [] | no_license | require 'csv'
require './Network'
data = CSV.read('spec/examples/iris.csv')
data.shuffle!
normalize = -> (val){val.to_f/10}
answercode = lambda do |ans|
if(ans == "Iris-setosa")
return 0.0
elsif ans == "Iris-versicolor"
return 0.5
else
return 1.0
end
end
train_data = Array.new
train_answers = Arr... | true |
244eb48e393d5ab75030a0c21a74b958c6e0c3bb | Ruby | luckypan123/learngit | /hearthstone/deck.rb | UTF-8 | 617 | 3.21875 | 3 | [] | no_license | class Deck
CAREER = ["magician","warrior","public"]
CHARGE = [0,1,2,3,4,5,6,7,8,9,10]
HEALTH = [1,2,3,4,5,6,7,8,9,10]
DAMAGE = [0,1,2,3,4,5,6,7,8,9,10]
TYPE = ["suite","magic"]
def initialize(career)
@cards = build(career)
end
def display
puts @cards
end
def shuffle
@cards = @cards.sh... | true |
b5f533535df0ceae48253f377501eb9a19c83569 | Ruby | coDeguZo/ruby-oo-self-cash-register-lab-dc-web-030920 | /lib/cash_register.rb | UTF-8 | 1,212 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :price, :items
def initialize(discount=0)
@total = 0
@discount = discount
@items = []
end
def add_item(title, price, quantity=1)
@price = price
@quantity = quantity
@total += price * quan... | true |
eb143b8518a60561c28efc8ca9f0c83d65ba85e2 | Ruby | BennyLouie/oo-relationships-practice-dumbo-web-82619 | /app/models/actor.rb | UTF-8 | 1,417 | 3.625 | 4 | [] | no_license | require 'pry'
class Actor
attr_reader(:name)
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def characters_played
Character.all.select do |character|
character.actor == self
end
end
def mo... | true |
62f56423fe5a13775c0121916df5d45ff99633da | Ruby | bluecat276/genomeviewer | /script/gt_server.lib/output.rb | UTF-8 | 3,598 | 2.84375 | 3 | [] | no_license | #
# output methods as image (png format) and image map on the png image
#
# these methods assume that the parameters are correct,
# that is they must be validated at higher level or can
# bring the gtserver to crash
module Output
require "benchmark"
#
# this saves the resulting image and map under an unique
#... | true |
7d1c6ffd3d5ea7746314b43ae4e38a059bb20355 | Ruby | agallant121/museo_1909 | /test/curator_test.rb | UTF-8 | 6,594 | 3 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/photograph'
require './lib/artist'
require './lib/curator'
class CuratorTest < Minitest::Test
def setup
@curator = Curator.new
end
def test_it_exists
assert_instance_of Curator, @curator
end
def test_it_has_no_photographs
asse... | true |
99b01c4d3fcfa49e24d4056d6450b596b458dada | Ruby | RowdyChildren/tts_classwork | /class3/lone.rb | UTF-8 | 103 | 3.140625 | 3 | [
"Unlicense"
] | permissive | x =1
until x == 100
if x % 2 == 0
puts "#{x} isn't 100 yet!"
end
x +=1
#puts "10 is 10" if x==10
end | true |
9252969520913b26fe426d9a9a1e4ed7cd77a35c | Ruby | magee/odms | /app/models/screening_datum_update.rb | UTF-8 | 3,553 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'csv'
#
# The ScreeningDatumUpdate#csv_file comes from ICF
#
# It contains updated case info which will be passed to USC
# to assist to correctly identifying controls?
#
class ScreeningDatumUpdate < ActiveRecord::Base
has_attached_file :csv_file,
YAML::load(ERB.new(IO.read(File.expand_path(
File.join(Rai... | true |
433379d44a28a20f67ac469d0e39d84a265599eb | Ruby | calo81/lovelyromcoms | /webapp/lib/utilities/recommendations/mapreduce/data_preparation/movie_lens_to_lovelyromcoms_id_map.rb | UTF-8 | 1,868 | 2.8125 | 3 | [] | no_license | require 'mongo'
conn = Mongo::Connection.new('localhost', 27017)
db = conn['lovelyromcoms_development']
coll = db['movies']
def replace_ids_with_titles_in_movie_lens_data
movie_lens_id_to_title={}
File.open('/tmp/data/ml-10M100K/movies.dat', 'r') do |file|
file.each_line do |line|
begin
splitted_... | true |
1be64467b5895892ed1ebdeaae73a8cc7dce088c | Ruby | jessiezhang2017/VideoStoreAPI | /db/seeds.rb | UTF-8 | 825 | 2.59375 | 3 | [] | no_license | JSON.parse(File.read('db/seeds/customers.json')).each do |customer|
Customer.create!(customer)
end
JSON.parse(File.read('db/seeds/movies.json')).each do |movie|
new_movie = Movie.new(movie)
new_movie.available_inventory = new_movie.inventory
new_movie.save
end
JSON.parse(File.read('db/seeds/rentals.json')).ea... | true |
94e1394ca50fa8e84bfa3cfef5683f099c7b0e3d | Ruby | kumamotone/TwitterCreateKataomoiList | /mimiListManage.rb | UTF-8 | 2,140 | 2.625 | 3 | [] | no_license | # coding: utf-8
require "twitter"
### gemのバージョンが4.xxと5.xxだと結構使えるメソッドの名前とかが違うので
### 現行のバージョンで動かない場合は実装を書きなおすかv4.xxを入れてください
### 参考:
### http://lance104.hatenablog.jp/entry/2014/03/10/234257
client = Twitter.configure do |config|
config.consumer_key = "" ## 要設定
config.consumer_secret = "" ## 要設定
config.oauth_... | true |
0de9417f8c82975dda8dd608eb28749fc7f01252 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/1130/source/11549.rb | UTF-8 | 321 | 3 | 3 | [] | no_license | def combine_anagrams(words)
index=Hash.new
data=Array.new
count=0
words.each do |word|
normalized_word=word.downcase.chars.sort.join
if index[normalized_word] == nil
index.store(normalized_word, count)
data << Array[word]
count+=1
else
data[index[normalized_word]] << word
end
end
data
en... | true |
7818d5a12a3bf48909afc384046ac3428e2ec18c | Ruby | flexera-public/rs-premium_free_trial | /CATs/deprecated/AppStack_CpuRamDriven.rb | UTF-8 | 30,403 | 2.5625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | #Copyright 2015 RightScale
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, softwar... | true |
bd28eb4639dbef50130d32cbbe885ed74fe90272 | Ruby | completerubyprogrammer/ruby-course | /project1/hello.rb | UTF-8 | 122 | 2.8125 | 3 | [] | no_license | # The code that follows prints
# various versions of hello world
puts "hello world"
print "hello world"
p "hello world!"
| true |
e15b35e0caad3d9e34bfa5d3dd0732b12a95b31d | Ruby | ndrewpacheco/RB101_2020 | /lesson_3/easy_1/q4.rb | UTF-8 | 374 | 3.78125 | 4 | [] | no_license | numbers = [1, 2, 3, 4, 5]
What do the following method calls do (assume we reset numbers to the original array between method calls)?
numbers.delete_at(1)
The arg that is being called upon `delete_at` dictates the index of the `numbers` array in which the indexed object is deleted.
numbers.delete(1)
THis means... | true |
13e87c5b565bc01cad0411eb9e3b5e3a554368f3 | Ruby | Harjitk/Ecosystem-HW | /bears.rb | UTF-8 | 509 | 3.5625 | 4 | [] | no_license | class Bear
attr_accessor :name, :type, :stomach
def initialize(name, type)
@name = name
@type = type
@stomach = []
end
def bear_name()
return @name
end
def bear_type()
return @type
end
def bear_has_empty_stomach()
if @stomach.empty?
return "Empty!"
end
end
def... | true |
51ba5d1315c1ce847426965250bfee49c2ba82a5 | Ruby | Niyatihd/aa_homeworks | /W1D3/W1D3_HW.rb | UTF-8 | 2,602 | 4.25 | 4 | [] | no_license | # Exercise 1 - sum_to
# Write a function sum_to(n) that uses recursion to calculate the sum from 1 to n (inclusive of n).
def sum_to(n)
if n == 1
return 1
elsif n < 1
return nil
end
n + sum_to(n - 1)
end
# Test Cases
p sum_to(5) # => returns 15
p sum_to(1) # => returns 1
p sum_to(9) # => returns 4... | true |
556cf971da75c5d10f05e0ba6204da83b5925f94 | Ruby | KiyotakaABE/RMS | /test/dummy-process.rb | UTF-8 | 922 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'thread'
class DummyProcess
# ratioを変化させる頻度
# RAND_FREQUENCY = 5
@@num = 0
def initialize
@ratio = rand(0.0..2.0)
@num = @@num
@@num += 1
my_print("initial:" + @ratio.to_s)
=begin
Thread.start{
loop{
sleep(RAND_FREQUENCY... | true |
84c1616dabcb43946e0eac3d984d326278c09797 | Ruby | manbooo/LikeLion_class_Ruby | /1day_Ruby/files_renaming.rb | UTF-8 | 1,151 | 3.6875 | 4 | [] | no_license | # 1. 해당 폴더로 들어간다.
# 2. 폴더 안을 돌면서 파일들의 이름을 가져온다
# 3. 각각의 이름을 변경한다. ex) 1.txt => jju1.txt
# cf) https://stackoverflow.com/questions/5530479/how-to-rename-a-file-in-ruby
# File.rename("test.txt", "hope.txt")
# cf) https://stackoverflow.com/questions/2512254/iterate-through-every-file-in-one-directory
# cf) https://stack... | true |
0f1376763708a41d716f10d739a4fd932cb67ec7 | Ruby | KF525/YesNoMaybeList | /app/models/activity.rb | UTF-8 | 614 | 2.71875 | 3 | [] | no_license | class Activity < ActiveRecord::Base
belongs_to :answer
validates :name, presence: true, uniqueness: true
def self.already_answered(current_user, relationship_id) #activities not answered by user in specific relationship
answered_names = []
answered = Answer.user_and_relationship_answers(relationship_id, ... | true |
8412969571b0c86ac6b56bb18d3db7ac3a6a9e31 | Ruby | rhomobile/rhodes | /res/build-tools/ruby-standalone/212/usr/local/lib/ruby/gems/2.1.0/gems/extlib-0.9.16/lib/extlib/try_dup.rb | UTF-8 | 419 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"MPL-1.1",
"BSD-3-Clause",
"GPL-2.0-only"
] | permissive | class Object
# Override this in a child if it cannot be dup'ed
#
# @return [Object]
def try_dup
self.dup
end
end
class TrueClass
def try_dup
self
end
end
class FalseClass
def try_dup
self
end
end
class Module
def try_dup
self
end
end
class NilClass
def try_dup
self
end
... | true |
ec1b420764f5646ae68ba262ed139c7717b6f0b6 | Ruby | ServioTRC/Design_Pattern_Quiz | /src/functions/score_handler.rb | UTF-8 | 2,551 | 3.15625 | 3 | [
"MIT"
] | permissive | # Final Project:
# Quiz Application with Microservices
# Date:
# 03-Dec-2019
# Authors:
# A01371719 Servio Tulio Reyes Castillo
# A01378840 Marco Antonio Rios Gutierrez
# A01379696 Ethan Isaac Bautista Trevizo
require 'date'
require 'j... | true |
5cb3dba965ff48e30bb3f811b5daddf18200bc97 | Ruby | johnjvaughn/ls_ruby_intro | /exercises/ex09.rb | UTF-8 | 296 | 3.625 | 4 | [] | no_license | h = {a:1, b:2, c:3, d:4}
puts h.inspect
puts
puts "1. Get the value of key `:b`"
puts "h[:b] is #{h[:b]}"
puts "2. Add to this hash the key:value pair `{e:5}`"
h[:e] = 5
puts h.inspect
puts "3. Remove all key:value pairs whose value is less than 3.5"
h.delete_if { |k,v| v < 3.5 }
puts h.inspect
| true |
e56bedf255bcfa075736f9a5ab1d432ff363383b | Ruby | AkhileshwarReddy/Data-Munging | /data-analyzer.rb | UTF-8 | 731 | 3.265625 | 3 | [] | no_license | class DataAnalyzer
attr_accessor :data, :columns, :min_diff, :item_header,:min_item
def initialize(data, columns, item_header_index)
@data = data
@columns = columns
@item_header = item_header_index
@min_diff = 1.0/0
end
def get_min_difference
data.each_with_index... | true |
c0a829ff88d98b51e4a5abce86a82a168735410b | Ruby | lichang333/bennystu | /fullstack-old/01-Ruby/05-Regular-Expressions/02-Anagrams/lib/anagrams.rb | UTF-8 | 1,110 | 3.953125 | 4 | [] | no_license | require "pry"
def anagrams?(a_string, another_string)
# TODO: implement the obvious method to test if two words are anagrams
array1 = a_string.downcase.gsub(/[^a-z]/i, '').split(//)
array2 = another_string.downcase.gsub(/[^a-z]/i, '').split(//)
# p array1
# p array2
array1 = array1.sort
array2 = array2.s... | true |
7c663c316968f556c722d091b66aa476012d86f4 | Ruby | alexandrebini/grokking-algorithms | /sort/merge_sort.rb | UTF-8 | 826 | 3.4375 | 3 | [] | no_license | # https://en.wikipedia.org/wiki/MergeSort
# https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort
module Sort
def self.merge_sort(list)
merge = lambda do |left, right|
p merge: { left: left, right: right }
next left if right.empty?
next right if l... | true |
697d77fdea2dd75a028387005141bae3602c44e9 | Ruby | cventeic/opengl-ruby | /util/deep_clone.rb | UTF-8 | 602 | 2.90625 | 3 | [
"Unlicense"
] | permissive | class Object
# Recursive clone vars in object
#
def deep_clone
return @deep_cloning_obj if @deep_cloning
@deep_cloning_obj = clone
@deep_cloning_obj.instance_variables.each do |var|
val = @deep_cloning_obj.instance_variable_get(var)
begin
@deep_cloning = true
val = val.... | true |
b8709ef118346711dcd5d5be4987906679fb0045 | Ruby | bryanesmith/bryan-shell-scripts | /xor | UTF-8 | 2,574 | 3.9375 | 4 | [] | no_license | #!/usr/bin/env ruby
#
# Returns xor of two numbers of equal length.
#
# Numbers must be hexadecimal or binary.
#
# Hexadecimal if start with 0x. E.g., 0x23.
#
# Binary is default, though you can optionally use 0b.
# E.g., 0101 or 0b0101.
#
# You can specify an optional output flag:
# --as-bin: output result as bina... | true |
36a39363da64e5c45b03edf9486b8659532fd173 | Ruby | darrylclarke/CodeCore | /week1/2015.08.12/conditional_assignment.rb | UTF-8 | 243 | 3.40625 | 3 | [] | no_license | # Only assign if it hasn't been assigned before
a ||= 10
a ||= 5
puts "This should be 10 --> #{a}"
b ||= "" # this is a valid object
b ||= "hello"
puts "This should be blank --> |#{b}|"
c ||= nil
c ||= 555
puts "This should be 555 --> #{c}"
| true |
8c2698c0beb553823989e36065aa157cd2159a86 | Ruby | StephenMayeux/prep_ruby_challenges | /factorials.rb | UTF-8 | 289 | 4.15625 | 4 | [] | no_license | # Factorials Method #1
def factorial1(number)
answer = 1
for num in 1..number
answer *= num
end
return answer
end
factorial1(5)
# Factorials Method #2
def factorial2(number)
range_of_numbers = (1..number).to_a
range_of_numbers.reduce { |a, b| a * b }
end
factorial2(5)
| true |
d116ad51b6d51356bb2d5f7d1e89f68edc8321fc | Ruby | vidoseaver/night_writer | /lib/to_braille_converter.rb | UTF-8 | 515 | 3.09375 | 3 | [] | no_license | require "./lib/library"
class ToBraille
def scanner(library_to_search)
library_to_search.each do |key, value|
if @input == key
@characters_in_order << value
end
end
@characters_in_order.last
end
def return_braille_lowercase
scanner(@letters_to_braille)
end
def retur... | true |
718127b7b4d9c1cfd8147967d3c59a8030097c36 | Ruby | Hugo-Vidal/Ejercicios_Ciclos | /solo_impares.rb | UTF-8 | 90 | 2.90625 | 3 | [] | no_license | n = ARGV[0].to_i
(n * 2 + 1).times do |i|
puts "#{i}" if i.odd? == true and i > 0
end | true |
f8b3a8495388eb02f2db902275f03910e7c4e073 | Ruby | HemalathaMurugan/square_array-prework | /square_array.rb | UTF-8 | 126 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
# your code here
answer =[]
array.each do|i|
#i**2
answer.push(i**2)
end
answer
end
| true |
541e7af80a0cfe54888f2adc7bae3620c900f002 | Ruby | pavelkvasnikov/endpoint-flux | /lib/endpoint_flux/tasks/endpoint_flux/generators/endpoint_flux/validations/predicates/password.rb | UTF-8 | 659 | 2.734375 | 3 | [
"MIT"
] | permissive | module Validations
module Predicates
module Password
module Methods
def password?(value)
rules = [
%r{[A-Z]}, # at least 1 uppercase character (A-Z)
%r{[a-z]}, # at least 1 lowercase character (a-z)
%r{\d}, # at least 1 digit (0-9)
%r{\W} ... | true |
b5d1288da780388e49c5fdba2d45b60a6184c290 | Ruby | jfaulk3/launch_school | /ruby-exercises/basics/exercise_three.rb | UTF-8 | 127 | 2.703125 | 3 | [] | no_license | movie = {
movie_one: "year_one",
movie_two: "year_two",
movie_three: "year_three"
}
movie.each {|key, value| puts value} | true |
5318445633b48cc144d0ad46e3af6b96addbd577 | Ruby | codeforfrankfurt/toilets_for_the_disabled | /lib/toilet_details.rb | UTF-8 | 1,283 | 3.171875 | 3 | [] | no_license | class ToiletDetails
HEADINGS = {
'Bewegungsfläche vor der Tür' => 'Tür - ',
'Kabinengröße' => 'Kabine - '
}
def initialize(attributes)
@attributes = {}
# making sure we have string keys
attributes.each do |key, value|
@attributes[key.to_s] = value
end
end
def self.from_scrapi... | true |
67d76f41b0df0ed32b0230f7d3f7b6ddb55e7e1b | Ruby | riekure/ruby-book | /caption5/hash_demo.rb | UTF-8 | 2,930 | 3.984375 | 4 | [] | no_license | currencies = { 'japan' => 'yen', 'us' => 'dollar', 'india' => 'rupee' }
currencies.delete('japan')
puts currencies.delete('italy') {
|key| "Not found: #{key}"
}
currencies.each do |key, value|
puts "#{key} : #{value}"
end
# シンボルはイミュータブルなので、破壊的な変更は不可能
symbol = :apple
# symbol.upcase!
# c:/Ruby25-x64... | true |
f488ccec12784d70384232ff6d338c5412eedb8d | Ruby | arnaldoaparicio/flash_cards | /spec/turn_spec.rb | UTF-8 | 949 | 3 | 3 | [] | no_license | require './lib/turn'
require './lib/card'
RSpec.describe Turn do
it 'exists' do
turn = Turn.new("Juneau", Card.new("What is the capital of Alaska?", "Juneau", :Geography))
expect(turn).to be_instance_of(Turn)
end
it 'has a guess' do
turn = Turn.new("Juneau", Card.new("What is the capital of Alaska... | true |
c52685cb99165c78b9ede2f72d7b620281d9750d | Ruby | BrunaNett/rack_lecture | /server.rb | UTF-8 | 2,343 | 2.734375 | 3 | [] | no_license | require 'rack'
require 'pry'
require 'pry-nav'
require 'socket'
class MyServer
STATUS_CODES = {200 => 'OK', 500 => 'Internal Server Error'}
attr_reader :app, :tcp_server, :port
def initialize(app, port = 3000)
@app = app
@port = port
end
def start
puts "Booting up Homegrown Webserver"
puts... | true |
b882dbeb83a5baa8d26c7a2b118a5319c134cc6d | Ruby | LaunchAcademy/extraterrestrial | /lib/et/runner.rb | UTF-8 | 3,272 | 2.59375 | 3 | [] | no_license | require "gli"
module ET
class Runner
include GLI::App
attr_reader :cwd
def initialize(cwd = Dir.pwd)
@cwd = cwd
end
def go(args)
version VERSION
pre { |_, _, _, _| check_config! }
desc "Initialize current directory as a work area."
skips_pre
command :init ... | true |
476633befccdc9f7354a51eb85085eae20f8d1f3 | Ruby | Dwightgnjohnson/ironyard_day4 | /homework.rb | UTF-8 | 1,052 | 4.4375 | 4 | [] | no_license | ### HOMEWORK DAY $ ###
# Define a Robot class
# A robot has a name
# A robot should have a method called 'say_hi' and it should return "Hi!"
# A robot should have a method called 'say_name' and it should return
# "My name is X" where X is the robot's name
class Robot
def initialize(name)
@name = name
end
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.