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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
215ff1cbd3980febc3e960dda5486ecc7d0f7f63 | Ruby | blackjackshellac/nautilus_scripts | /lib/nautilus_scripts.rb | UTF-8 | 3,330 | 2.6875 | 3 | [
"MIT"
] | permissive |
module Nautilus
GEOMETRY_RE=/(?<w>\d+)x(?<h>\d+)\+(?<x>\d+)\+(?<y>\d+)/
GEOMETRY_KEYS=[:x, :y, :w, :h]
# Document the responsibility of the class
#
# == Nautilus::Scripts class
#
# Helpers for handling NAUTILUS_SCRIPT environment variables in ruby scripts placed in
# ~/.local/share/nautilus/scripts
#
... | true |
091cf0fcd9b3f0a2acff2273471e7388d5325dbf | Ruby | MichelCance/cryptoscrapper | /lib/crypto_scrap.rb | UTF-8 | 1,094 | 3.328125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri' # Obligatoire avec nokogiri pour charger une page sur le web
def init_nokogiri(url)
page = Nokogiri::HTML(open(url))
return page
end
def main
page = init_nokogiri("https://coinmarketcap.com/all/views/all/")
if page != nil
symbol_xpath = '//div[@class="cm... | true |
6dfaae1b5164c25770b34e19602a105ca77136f1 | Ruby | travislavery/rails-portals | /app/helpers/quests_helper.rb | UTF-8 | 197 | 2.5625 | 3 | [] | no_license | module QuestsHelper
def users_with_links(quest)
list = quest.users.map do |user|
user_with_link(user)
end
list.join(" ")
end
def user_with_link(user)
link_to user.name, user
end
end
| true |
a6fe577dbdc678859ae9ef78c990801183259cb6 | Ruby | andyatkinson/recursion-examples | /fibonacci.rb | UTF-8 | 292 | 3.828125 | 4 | [] | no_license | #
# the number in the fibonacci sequence (sum of previous two numbers)
# based on the input
#
# no memoization
# O(n^2) exponential time complexity for recursive version
def fibonacci(n)
if n <= 1
n
else
fibonacci(n - 1) + fibonacci(n - 2)
end
end
puts fibonacci(ARGV[0].to_i)
| true |
be35886fdc31212341b9550d0d6863658704d531 | Ruby | yoko-hashimoto/hundred_question_drill | /chapter_3/british_article.rb | UTF-8 | 369 | 2.859375 | 3 | [] | no_license | require 'pathname'
require 'json'
def british_article
path = Pathname("jawiki-country.json")
File.foreach(path) { |line|
# parseする事でハッシュ形式にする
hash = JSON.parse(line)
# paeseされたハッシュのキーはシンボルではなく文字列になる
if hash["title"] == "イギリス"
return hash["text"]
end
}
end
| true |
cc84f9126c7c3ee15e9841ce03a1c9439619d157 | Ruby | asmolentzov/backend_prework | /day_6/objects_ex2.rb | UTF-8 | 1,533 | 4.40625 | 4 | [] | no_license | # From https://launchschool.com/books/oo_ruby/read/classes_and_objects_part1
class GoodDog
def initialize(name)
@name = name
end
def name # This was renamed from "get_name"
@name
end
def name=(n) # This was renamed from "set_name="
@name = n
end
def speak
"#{@name} says arf!"
end... | true |
f2b22750fda14624a6c03b1385375ab482313e16 | Ruby | deeptailor/homework | /w1d5/stack.rb | UTF-8 | 264 | 3.3125 | 3 | [] | no_license | class Stack
attr_reader :ivar
def initialize
@ivar = []
end
def add(el)
@ivar << el
end
def remove
@ivar.pop
end
def show
@ivar
end
end
# test = Stack.new
# test.add(5)
# test.add(4)
# test.add(3)
# test.remove
# p test.show
| true |
161ee1fa99e6079d562f4845e75ba7cb40234f72 | Ruby | holysugar/gbf-imascg-idol-network | /generate.rb | UTF-8 | 2,336 | 2.65625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'csv'
require 'json'
require 'erb'
csv = CSV.read('idol.csv')
nodedata = csv.each_with_index.
select { |l,idx| idx > 0 && l[0] }.
map { |l, idx|
{
id: idx.to_i,
label: l[0],
group: l[1],
}
}
edges = []
csv.each_with_index do |l, _y|
l.each_with_index do ... | true |
6ce7f6c8e92b3759fcc6b81320d7e324d36fea26 | Ruby | JTorr/Homework | /7.30/hangman_spec.rb | UTF-8 | 1,115 | 3.390625 | 3 | [] | no_license | require "minitest/autorun"
#Uncomment requirement code when file is created
#require "./hangman.rb"
describe Hangman do
it "isn't finished when it starts" do
game = Hangman.new
assert game.finished? == false
end
it "removes letter from alphabet after it is guessed" do
game = Hangman.new("bird")
... | true |
9292945bcb6286ccfff1e10790fc9b42737bb557 | Ruby | bluebottlecoffee/cropster | /lib/cropster/response/formatted_response_item.rb | UTF-8 | 2,393 | 2.6875 | 3 | [
"MIT"
] | permissive | module Cropster::Response
class FormattedResponseItem
require 'cropster/response/location'
require 'cropster/response/weight'
require 'cropster/response/project'
require 'cropster/response/source'
attr_accessor :id,
:id_tag,
:name,
:created_... | true |
2eea52283eb97716c3a7ac88e7a69604368ba3a9 | Ruby | morrow/tutorials | /ruby/doubler.rb | UTF-8 | 500 | 4 | 4 | [] | no_license | def double(input)
# convert input to integer and double it
return input.to_i * 2
end
# prompt user for number (we use print here instead of puts because print does not add a newline at the end)
print "Enter a number to double: "
# capture user input, strip any newline characters
number = gets.strip
# call double... | true |
700bcd688ace92e882bb1e51a04bd44a39e52693 | Ruby | Hyan18/bank-tech-test | /lib/bank.rb | UTF-8 | 877 | 3.5 | 4 | [] | no_license | require_relative 'bank_log'
require_relative 'statement'
class Bank
MINIMUM_BALANCE = 0
def initialize(bank_log = BankLog.new)
@bank_log = bank_log
@balance = 0
end
def deposit(amount, date = Time.now)
@balance += amount
@bank_log.add(type: :deposit, amount: amount, balance: @balance, date: d... | true |
e9ea01346e7fc6e95a43fd142c8ba0a43e7f0700 | Ruby | austinmccalley/lord-evan-bot | /main.rb | UTF-8 | 4,146 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'discordrb'
require 'yaml'
CONFIG = YAML.load_file('config.yml')
bot = Discordrb::Commands::CommandBot.new token: CONFIG['token'], prefix: CONFIG['prefix']
# praise count mutex
praise_mutex = Mutex.new
bot.command(:ping) do |event|
ping_ts = event.message.timestamp
pong_ms... | true |
9370b754417d94972b71c7a79a89162f91ad2aa0 | Ruby | Freaky/flash_find | /lib/flash_find.rb | UTF-8 | 10,548 | 2.65625 | 3 | [] | no_license |
require 'pathname'
require 'set'
require 'thread'
require 'thread_safe'
require 'concurrent'
require 'flash_find/version'
# == FlashFind
#
# High performance multi-threaded directory walker.
#
# `#push` directories to be walked, `#prune` entries you don't want to recurse
# into, and `#each` over the files and direct... | true |
8fb93b1ef09914457ee1b715bf5384bd6c2f300c | Ruby | ChallengeYourself/todo-ruby-basics-prework | /lib/ruby_basics.rb | UTF-8 | 335 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1, num2)
quotient = num1/num2
return quotient
end
def assign_variable(value)
name = value
return name
end
def argue(arg)
return arg
end
def greeting(greeting, name)
end
def return_a_value
return "Nice"
end
def last_evaluated_value
return "expert"
end
def pizza_party(fav = "cheese")
... | true |
41f531d373d2d283865c53cee8baf9f054fd96c0 | Ruby | theodoro/rubybasico | /letra.rb | UTF-8 | 292 | 3.703125 | 4 | [] | no_license | puts 'Olá, mundo'
puts ''
puts 'Até logo.'
puts "Aritimética das Strings"
puts 'Eu gosto de' + 'torta de maçã.'
puts 'Eu gosto de ' + 'torta de maçã'
# Multiplicação de String
puts 'piscar ' * 4
puts 12 + 12
puts '12' + '12'
puts '12 + 12'
puts 2 * 5
puts '2' * 5
puts '2 * 5'
| true |
8e32688986c0a7354048161ac07e71aa65a8cccf | Ruby | emilfolino/grillcon | /tsp.rb | UTF-8 | 1,631 | 3.28125 | 3 | [] | no_license | universities = {
'BTH' => {"lat" => 56.18, "long" => 15.59},
'Uppsala' => {"lat" => 59.85, "long" => 17.63},
'Lund' => {"lat" => 55.71, "long" => 13.20},
'KTH' => {"lat" => 59.34, "long" => 18.07},
'Chalmers' => {"lat" => 57.68, "long" => 11.97},
'Luleå' => {"lat" => 65.61, "long" => 22.14},
... | true |
3d422eb66749c62be699d16a628ed1969be80aed | Ruby | jasont01/ruby-tic-tac-toe | /player.rb | UTF-8 | 668 | 3.609375 | 4 | [] | no_license | class Player
attr_accessor :name, :marker
def initialize(marker)
print "Enter Player's name (#{marker}): "
@name = gets.chomp
@marker = marker
end
def move(board)
print "Enter coordinates for #{name}'s move: "
coordinates = gets.chomp
until(/[abc]/.match(coordinates[0]) && /[123]/.mat... | true |
0a1ad110f2d31a1c15de4446b3937a91f3b6ef1f | Ruby | guncho2/bloccit | /spec/controllers/question2s_controller_spec.rb | UTF-8 | 3,694 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
include RandomData
RSpec.describe Question2sController, type: :controller do
let (:my_question2) do
Question2.create(
id: 1,
title: RandomData.random_sentence,
body: RandomData.random_paragraph,
resolved: false
)
end
describe "GET #index" do
it "returns http suc... | true |
13f6d74f9d60660307d234b274553897d2f9e7db | Ruby | RasmusHaarslev/ProjectEuler | /problems/001-100/007/007.rb | UTF-8 | 132 | 3.140625 | 3 | [] | no_license | require 'prime'
count = 0
prime = 0
until count == 10001
prime += 1
if Prime.prime?(prime)
count += 1
end
end
puts prime | true |
c48b983d167cf4568b561abbb7edf282c9a1d15d | Ruby | seangibat/mks-coursework-2 | /cars.rb | UTF-8 | 1,372 | 3.734375 | 4 | [] | no_license | class Car
@@total_car_count = 0
@@cars_per_color = Hash.new
# class var total_car_count getter
def self.total_car_count
@@total_car_count
end
def self.most_popular_color
@@cars_per_color.max_by { |k, v| v }[0]
end
def to_s()
"I'm a car! I've driven #{@distance} and have #{@fuel} gallons gas left"
end
... | true |
17fdd64aeebd36b45d289086db538635640e13e8 | Ruby | Alajuwon/first_program | /animals.rb | UTF-8 | 377 | 3.875 | 4 | [] | no_license | puts "what is your favorite animal?"
animal = gets.chomp.downcase
if animal == "dog"
puts "Wooofff"
elsif animal == "cat"
puts "Meoooewww"
elsif animal == "donkey"
puts "heeehuuuuunhhh"
elsif animal == "horse"
puts "neigh"
elsif animal == "lion"
puts "roar"
elsif animal == "snake"
puts "hiissssssss"
elsif anima... | true |
61d5ed7f5d5677a5d89e5cb4e638abef3eb00dd7 | Ruby | slague/HTTP | /test/http_game_test.rb | UTF-8 | 876 | 2.5625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/my_server'
require './lib/http_game'
require 'faraday'
class GameTest < Minitest::Test
def test_it_handles_start_game
response = Faraday.post 'http://127.0.0.1:9292/start_game'
result = "<html><head></head><body>Good luck!</body></html>"
... | true |
caba879b5bc2e6a9a5183e8adf7095b595f40ee5 | Ruby | hamatata/http-interceptor | /libs/handler.rb | UTF-8 | 2,068 | 2.84375 | 3 | [] | no_license | require 'ritm'
Ritm.on_request do |req|
if req.request_uri.host.start_with? 'ui-dev.horizon'
puts '#'*10
puts 'this is HORIZZZON'
end
puts req.request_uri
if req.request_uri.host.include?('addresses?')
puts "THIS IS ADDRESSES!!!"
req.request_uri.host = 'http://korrespondent.net'
end
end
m... | true |
1f98331f09fb305792e704df6f2851c60af54a49 | Ruby | jarib/jschematic | /lib/jschematic/attributes/minimum.rb | UTF-8 | 393 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'jschematic/element'
module Jschematic
module Attributes
class Minimum
include Jschematic::Element
attr_reader :minimum
def initialize(minimum)
@minimum = minimum
end
def accepts?(number)
return true unless Numeric === number
(number >= minimum) |... | true |
66fe102bc3da4ecf9bca39e669604ecb40b7f726 | Ruby | hwangjf/oo-banking-nyc-web-042318 | /lib/bank_account.rb | UTF-8 | 629 | 3.75 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class BankAccount
attr_accessor :balance, :status
attr_reader :name
def initialize(name)
@name = name
@balance = 1000
@status = "open"
end
#use method= when setting
#in this case we use attr_accessor to set only using below
#method to call
def deposit(amount)
... | true |
4edc5c5cb84cee928cf53851e808a16f2da2ef8e | Ruby | holyketzer/ctci_v6 | /ruby/spec/02_linked_lists/2_4_partition.rb | UTF-8 | 1,538 | 3.109375 | 3 | [
"MIT"
] | permissive | # time = O(n), mem = O(1)
def partition_b(head, x)
l = head
r = head.next_node
while l.value >= x do
swap_values(l, r)
r = r.next_node
end
while r do
if r.value < x
l = l.next_node
swap_values(l, r)
end
r = r.next_node
end
head
end
def swap_values(a, b)
tmp = a.value... | true |
b51a72c3d3d0714da07c7b85b0b903d4b73c21b1 | Ruby | shadchnev/6-weeks-test | /editor.rb | UTF-8 | 201 | 2.953125 | 3 | [] | no_license | require_relative 'command'
class Editor
def initialize
@command = Command.new
end
def execute
@command.parse(user_input)
end
private
def user_input
gets.chomp
end
end | true |
4bf27bba7d596b05c70ca641747be40c018fd6a9 | Ruby | ftt9282/oop_with_ruby | /tic_tac_toe.rb | UTF-8 | 2,545 | 3.828125 | 4 | [] | no_license | class Player
@@total_players = 0
attr_reader :player_name, :player_symbol
def initialize(player_name)
@player_name = player_name
assign_letter
end
private
def assign_letter
if @@total_players == 0
@player_symbol = 'X'
else
@player_symbol = 'O'
end
@@total_players += 1
... | true |
d4c99e681f9a714593524b849888da304951552f | Ruby | danhealy/danhealy_tictactoe | /lib/terminal.rb | UTF-8 | 2,150 | 3.40625 | 3 | [] | no_license | # frozen_string_literal: true
# Responsible for terminal interactions only, using TTY::Prompt
class Terminal
attr_accessor :prompt, :cur_game
def initialize(tty = TTY::Prompt.new)
@prompt = tty
end
def run
@prompt.say "Welcome to Tic-Tac-Toe"
new_game
@prompt.say "Thanks for playing."
end
... | true |
766ed24ea1a0ffb9658ceeb724dab2840987e0e2 | Ruby | TheLastSultan/W2D4 | /time_complexity/two_sum.rb | UTF-8 | 233 | 3.0625 | 3 | [] | no_license | def two_sum(arr,target)
arr.length.times do |i|
arr.length.times do |j|
next if i == j
return [arr[i],arr[j]] if arr[i] + arr[j] == target
end
end
false
end
#n ^ 2
arr = (-150..100).to_a
p two_sum(arr,0)
| true |
b360e6ff7024a3eafa25ad137fbe002d45c85a16 | Ruby | jonathanhefner/pleasant_path | /test/pathname_test.rb | UTF-8 | 12,522 | 2.890625 | 3 | [
"MIT"
] | permissive | require "test_helper"
class PathnameTest < Minitest::Test
def test_null_constant
assert_equal File::NULL, Pathname::NULL.to_s
end
def test_to_pathname
path = Pathname.new("path/to/file")
assert_same path, path.to_pathname
end
def test_op_caret
dirname = Pathname.new("path/to")
path = ... | true |
1d2e2f72ad9d78ce42932e0598bb041c06a8c003 | Ruby | glennr/runconf | /app/models/map_scraper.rb | UTF-8 | 366 | 2.546875 | 3 | [] | no_license | class MapScraper
def scrape_map(race_id)
race = db.load! race_id
if race.runkeeper_url.present?
html = HTTParty.get race.runkeeper_url
race.map_points = html.scan(/"latitude":(\d+\.\d+),"longitude":(\d+\.\d+)/).map{|pair| [pair[0].to_f, pair[1].to_f]}
db.save race
end
end
private
... | true |
45da7470f71e1b292dd2a4d27cd6e9e5ced1df93 | Ruby | arsy209/battle-me | /app/models/comp_battle_engine.rb | UTF-8 | 1,894 | 3.109375 | 3 | [] | no_license | class CompBattleEngine
def initialize(pokemon_battle:)
@pokemon_battle = pokemon_battle
@player = @pokemon_battle.pokemon1
@ai = @pokemon_battle.pokemon2
end
def start_ai_battle?
result = []
result << validate_state?
result << validate_battle_type?
result << validate_health_point?
result.all?
end
... | true |
c463cf6a8a3023186fac9370f833e92baf97a3b5 | Ruby | jeremymturner/exercism | /ruby/hamming/hamming.rb | UTF-8 | 433 | 3.359375 | 3 | [] | no_license | #!/usr/bin/env ruby
class Hamming
def self.compute(s1,s2)
# Fail if lengths are not the same
if s1.length != s2.length
return raise(ArgumentError)
end
# Calculate the number of inequal chars
hamming_num = 0
for i in 0..s1.length
hamming_num += 1 if s1[i] != s2[i]
end
return hamm... | true |
e1dc7f33d40e585f453d669bf5106a2c3812ae3e | Ruby | diegoffnogueira/ruby-iniciante | /heranca.rb | UTF-8 | 313 | 2.921875 | 3 | [] | no_license | class Automovel
def self.tipo_cambio
puts "Manual"
end
def acelera
puts "Acelerando automovel..."
end
end
class CarroNovo < Automovel
def acelera
puts "Verificando equipamentos..."
super
end
end
carro = CarroNovo.new
puts carro.acelera
Automovel.tipo_cambio
CarroNovo.tipo_cambio
| true |
19cb0079cbb349758ea901ecf787c01f4cb80298 | Ruby | nazizi1/ITSC3155 | /ruby_calisthenics1/lib/fun_with_strings.rb | UTF-8 | 481 | 3.296875 | 3 | [] | no_license | module FunWithStrings
def palindrome?
self.gsub(/\W/,'').downcase == self.gsub(/\W/,'').downcase.reverse
end
def count_words
h = Hash.new(0)
string = self.downcase.gsub(/[^a-z0-9 ]+/i, '')
string.split.each { |x| h[x] = h[x] + 1 }
h
end
def anagram_groups
string = self.downcase.split.g... | true |
1f0ee52ac011fc3284d7d309eb53f727d55cc3f7 | Ruby | Kraykina/ruby_course | /head_first_ruby/chapter4/boat.rb | UTF-8 | 293 | 3.625 | 4 | [] | no_license | class Boat
def initialize(name)
@name = name
end
end
class PowerBoat < Boat
def initialize(name, motor_type)
super(name)
@motor_type = motor_type
end
def info
puts "Name: #{@name}"
puts "Motor Type: #{@motor_type}"
end
end
boat = PowerBoat.new("Guppy", "outboard")
boat.info
| true |
fdbd1aa3faa6f339023e71d5ebd16c4a479f50f6 | Ruby | cnaseeb/test | /test.rb | UTF-8 | 95 | 2.59375 | 3 | [] | no_license | #This is my first Ruby program
puts "Hello World!"
# Format this code
puts "Fix indentation" | true |
b39ea89c71539491ff984ac4806678991acb969e | Ruby | fx/polymer | /lib/polymer/project.rb | UTF-8 | 6,285 | 2.9375 | 3 | [
"BSD-3-Clause"
] | permissive | module Polymer
# Represents a directory in which it is expected that there be a
# configuration file, and source images.
#
# The Project class exists mostly to make CLI tasks simpler; if you're using
# Polymer within your own library, you may prefer to create Sprite instances
# without using a Project.
#
... | true |
d89ec5ff624ab50bdb9563da08e3f8b647fca2a9 | Ruby | tim0414/ruby_practice | /equal_example.rb | UTF-8 | 148 | 3.359375 | 3 | [] | no_license |
class BasicObject
def equal?(o)
"using equal?"
end
end
o1 = BasicObject.new
o2 = BasicObject.new
print o1.equal?o2
print o1==o2
| true |
bd52db4e6fff2d5f4cda721d9c4af03466563615 | Ruby | americac/alice | /alice/filters/disoriented.rb | UTF-8 | 289 | 2.6875 | 3 | [
"MIT"
] | permissive | module Alice
module Filters
class Disoriented
def process(text)
to_process = "#{text}"
directions = Alice::Place::DIRECTIONS.sort{|a,b| rand(10) <=> rand(10)}
to_process.gsub!(/east|west|north|south/) { directions.pop }
end
end
end
end | true |
e40a5b811b8ef0503417c5ae4daa83e0c50456cd | Ruby | marcosfparreiras/cracking-the-code-interview-hacker-rank | /app/spec/data-structure/04_linked_list_detect_a_cycle_spec.rb | UTF-8 | 3,611 | 3.15625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../../src/data-structures/04_linked_list_detect_a_cycle'
describe DataStructures::LikedList::Node do
let(:node1) { described_class.new(19) }
let(:node2) { described_class.new(42, node1) }
it 'has data' do
expect(node2.data).to eq(42)
end
it 'has next' do... | true |
1864df3dc8e891c392beafd4ce0850741f1d39cf | Ruby | entp/ruby-openid | /test/test_accept.rb | UTF-8 | 4,532 | 2.703125 | 3 | [
"Apache-2.0",
"Ruby"
] | permissive | require "test_helper"
require 'openid/yadis/accept'
require 'openid/extras'
require 'openid/util'
require 'test_util'
module OpenID
class AcceptTest < Test::Unit::TestCase
include TestDataMixin
def getTestData()
# Read the test data off of disk
#
# () -> [(int, str)]
lines = read_da... | true |
c3f4505e75c4f0bcef4890d501064bf37c9cf423 | Ruby | jyschwrtz/AppAcademyProjects | /W2D1/Chess/sliding_piece.rb | UTF-8 | 922 | 3.15625 | 3 | [] | no_license | require 'byebug'
module SlidingPiece
def moves
grow_unblocked_moves_in_dir
end
private
def move_dirs
end
def horizontal_dirs
[
[1, 0],
[0, 1],
[-1, 0],
[0, -1]
]
end
def diagonal_dirs
[
[1, 1],
[-1, 1],
[1, -1],
[-1, -1]
]
end
def grow_unblocked_... | true |
6acbdb3a1c04fc4f4b0bcc1abe0bbf2da677b1cc | Ruby | SK-Sam/active_cell | /lib/cell.rb | UTF-8 | 643 | 3.671875 | 4 | [] | no_license | # Cell is only responsible for either being a target and/or active.
# In this project, there will be no reason to un-target or
# de-activate cells. The simulation should be able to check/set if the
# cell is a target/active using getter/setter methods
class Cell
def initialize
@active = false
@target = fal... | true |
598980705d4ab92e65746dd57632f2907a908fc7 | Ruby | thesteady/warmup-exercises | /20-triangle/triangle.rb | UTF-8 | 752 | 3.625 | 4 | [] | no_license | class TriangleError < StandardError
end
def triangle(side_a, side_b, side_c)
#confirm a valid triangle
all_sides = [side_a, side_b, side_c]
confirm_valid_triangle(all_sides)
if side_a == side_b && side_b == side_c
:equilateral
elsif side_a == side_b || side_b == side_c || side_a == side_c
:isosceles... | true |
afcdbfb7e02776529cbb8b272ed6179d8d992328 | Ruby | ErdemOzgen/leetcode | /ruby/3-Longest-Substring-Without-Repeating-Characters.rb | UTF-8 | 352 | 3.296875 | 3 | [
"MIT"
] | permissive | def length_of_longest_substring(s)
return 1 if s.length == 1
return 0 if s.length.zero?
window = []
appear = {}
max = 0
s.each_char do |c|
if appear.key?(c)
while appear.key?(c)
appear.delete(window.shift)
end
end
window << c
appear[c] = c
max = window.length if wind... | true |
08a629c783c62205bdcffaee92f34fcb5767d2b5 | Ruby | htan712/sep-assignments | /01-data-structures/03-linked-lists/linked_list_bench.rb | UTF-8 | 700 | 3.296875 | 3 | [] | no_license | require 'benchmark'
require_relative 'node'
require_relative 'linked_list'
list = LinkedList.new
mynode = Node.new("hi")
n = 10000
arr = []
## Benchmark for array.push vs. list.add_to_tail
Benchmark.bm do |x|
x.report("add_to_tail:") do
for i in 1..n do
list.add_to_tail(mynode)
end
end
x.report("array pus... | true |
ce016cb178ec4ae8b624421ed92ed481d63bd9ff | Ruby | cde/algorithms | /leetcode/list/LRUCache.rb | UTF-8 | 1,521 | 3.6875 | 4 | [] | no_license | require 'pry'
class Node
attr_accessor :key, :data, :next, :previous
def initialize(key, data)
@key = key
@data = data
@next = nil
@previous = nil
end
end
class LRUCache
attr_reader :head, :tail, :cache, :capacity
def initialize(capacity)
@head = Node.new('dh',0)
@tail = Node.new('dt... | true |
38d6198fd56dd7026e0075aba84b8edc0c17f4cf | Ruby | arietah8545/05-jukebox-cli-lab | /lib/jukebox.rb | UTF-8 | 1,804 | 3.46875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | songs = [
"Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"Phoenix - Consolation Prizes",
"Harry Chapin - Cats in the Cradle",
"Amos Lee - Keep It Loose, Keep It Tight"
]
def help... | true |
38e36e6ab05c9c3284d9c1f2d7b9b182b0158e1c | Ruby | Draganovic/http-yeah-you-know-me | /lib/parser.rb | UTF-8 | 1,177 | 2.8125 | 3 | [] | no_license | require 'socket'
require './lib/output'
class Parser
attr_reader :diagnostic
def initialize
@client = nil
@diagnostic = {}
end
def parse(client)
@client = client
request_lines = []
while line = @client.gets and !line.chomp.empty?
request_lines << line.chomp
end
populate_diag... | true |
589cf5f3aa6a01b1051d0e70a3338257dcc185b0 | Ruby | laynef/RailsPlusPlus | /lib/railspp.rb | UTF-8 | 2,879 | 2.8125 | 3 | [
"MIT"
] | permissive | require_relative './commands/initialize.rb'
require_relative './commands/api_docs.rb'
require_relative './commands/model.rb'
require_relative './commands/make_test.rb'
require_relative './commands/update_version.rb'
require_relative './help/api_docs.rb'
require_relative './help/documentation.rb'
require_relative './hel... | true |
276545cf9dc0d30b257b64f24391263cf3fcd47b | Ruby | bchase/dotfiles | /scripts/json.rb | UTF-8 | 351 | 2.90625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'json'
require 'pp'
# # given JSON: {"data":{"url":"https://foo.bar/baz.boo","id":1}}}
# $ curl localhost:4000/foo/1 | xargs -0 ./json.rb data url
# https://foo.bar/baz.boo
str, keys = ARGV.pop, ARGV || []
json = JSON.parse str.chomp
unless keys.empty?
while key = keys.shift
json ... | true |
3becce6302d7b36a1d393ab5b7e91afad36795be | Ruby | mcaers/rainforest_in_class | /test/unit/product_test.rb | UTF-8 | 1,716 | 3.015625 | 3 | [] | no_license | require 'test_helper'
class ProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
setup do
@p = FactoryGirl.create(:product)
assert @p.valid?
end
# def test_must_have_a_description
test "must have a description" do
@p.description = ""
refute @p.valid?
end
... | true |
d286a03a888a01881afd49f1ce98b1d340580075 | Ruby | AlexMMcConnell/night_writer | /lib/night_writer.rb | UTF-8 | 233 | 2.59375 | 3 | [] | no_license | require_relative 'writer'
class NightWriter
def write
text_file_names = ARGV
writer = Writer.new(text_file_names)
writer.creation_message
writer.write if File.file?(text_file_names[0])
end
end
NightWriter.write
| true |
10f9dd4723d83d4f15095882610152e9adcc2f8d | Ruby | Team-JD/JDChess | /spec/models/pawn_spec.rb | UTF-8 | 3,355 | 2.625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Pawn, type: :model do
describe "#valid_move?" do
it "should return false when it moves from A2 to A8" do
game = Game.new
pawn1 = Pawn.new
game.pieces << pawn1
pawn1.location = "A2"
pawn1.piece_status = "Active... | true |
4688ea1adcf07837d8873a4e0f497e476c94e33d | Ruby | derailed/bigbertha | /lib/bigbertha/ref.rb | UTF-8 | 1,629 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'uri'
module Bigbertha
class Ref
include Bigbertha::Action
attr_reader :url, :uri
def self.evt_value; :value; end
def self.evt_child_added; :add_child; end
def self.evt_child_changed; :mod_child; end
def self.evt_child_removed; :rm_child; end
def self.evt... | true |
5839b2b2e1aa5e54f70780648eb70a2fb90e306a | Ruby | BrennanE1/summercamp | /DAY 3/RUBY/First/sixth.rb | UTF-8 | 279 | 3.4375 | 3 | [] | no_license | exam_scores = [ 25, 55, 60, 70, 89 ]
exam_scores.push 90
exam_scores.push 100
exam_scores.push 67
exam_scores.push 80
puts exam_scores
exam_scores.each do |score|
if score > 80
puts score.to_s + "passed"
else
puts score.to_s + "failed"
end
end | true |
6817053990b5e2e4d361be7334778fc53dd8463a | Ruby | joshy91/Launch-School | /exercises/small_problems/right_triangles.rb | UTF-8 | 103 | 3.40625 | 3 | [] | no_license | def triangle(num)
for i in (1..num)
puts (' '*(num-i) + '*'*i)
end
end
triangle(5)
triangle(9) | true |
9db8454837938c719d1448764672c7a6a93d6eaa | Ruby | timestep/crowdfunder | /test/integration/project_flows_test.rb | UTF-8 | 2,184 | 2.59375 | 3 | [] | no_license | require 'test_helper'
class ProjectFlowsTest < ActionDispatch::IntegrationTest
test 'browsing projects' do
#create 3 projects
# binding.pry
project1 = FactoryGirl.create(:project, :title => 'Project 1')
project2 = FactoryGirl.create(:project, :title => 'Project 2')
project3 = FactoryGirl.create(:project,... | true |
fa6b3962aed506bf30166dc9cf6490163b318d22 | Ruby | jakeb4shelby/LearnRuby | /3Methods/multiply.rb | UTF-8 | 60 | 3.046875 | 3 | [] | no_license | def multiply(a, b)
return a * b
end
puts multiply(4,5)
| true |
123067afe0862eaca74f5a740ecd2452661c94e2 | Ruby | styrken/store-ratings | /lib/store-rating.rb | UTF-8 | 1,468 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'open-uri'
require 'net/http'
require 'uri'
require 'json'
module StoreRating
# Rating
#
# Helper method to return rating depending on parameters given, either for iOS or Android
def self.rating(app_id, country = nil)
if app_id.to_i > 0 && country != nil # iOS
return ios_r... | true |
3502d19eaaf474f2488e7de8ad2ca1a7d247e2d0 | Ruby | MMKubicki/MachLearn-ProgTask | /assignment 5/functions.rb | UTF-8 | 2,071 | 3.5625 | 4 | [] | no_license | # use sqrt as member function of float
class Float
def sqrt
Math.sqrt(self)
end
end
# format input data
def create_sample(data)
{class: data.first.upcase, position: data[1..-1]}
end
# class performing IB2
class IB2
attr_reader :k, :casebase
# set k of kNN
def initialize(k)
@k = k
@casebase =... | true |
c1556d8a1dd873c458d9c49782dda1c1a925bc58 | Ruby | QWYNG/Review_Gacha | /array_extension.rb | UTF-8 | 333 | 2.65625 | 3 | [] | no_license | module SlackFormat
refine Array do
def sample_except_for(element)
reject { |id| id == element }.sample
end
def format_for_slack
text = []
each do |element|
text << format_id(element)
end
text.join
end
end
private
def format_id(element)
"<@#{element}>\... | true |
54b43021e08d2004bde507ee270cb0cb172ec62b | Ruby | viki-org/subber-gem | /lib/subber/formatter/srt.rb | UTF-8 | 2,012 | 2.9375 | 3 | [
"MIT"
] | permissive | module Subber::Formatter
class Srt < Base
LF_REGEX = /\n/
CRLF = "\r\n".freeze
class << self
# @param subtitles [Array<Subber::Subtitle>]
# @return [String]
#
def format(subtitles)
subtitle_texts =
subtitles.map do |subtitle|
convert_subtitle_to_text(... | true |
007d2720ef1e4bc06073cf88210e13d1f4d68dc7 | Ruby | bstiber/launch_school_exercises | /small_problems_2nd_round/ruby_basics/loops1/8.rb | UTF-8 | 515 | 4.71875 | 5 | [] | no_license | # Given the array of several numbers below, use an until loop to print each number.
## ** Pseudo - code **
# input
# - integer
# output
# - integer
# rules
# - use a until loop, that performs a function until a condition is met
# The until loop executes while a condition is false:
# - until number size == 0 or num... | true |
575b8208c8ba1f8c6a371f614e7737e9f433d92f | Ruby | ArmandoAmador/codewars | /ruby/8_kyu/add_item_to_an_array/spec/add_item_to_an_array_spec.rb | UTF-8 | 424 | 3.28125 | 3 | [] | no_license | # Add the value "codewars" to the websites array.
# After your code executes the websites array should == ["codewars"]
# The websites array has already been defined for you using the following code:
require_relative '../add_item_to_an_array'
RSpec.describe AddItemToAnArray do
it "adds an item to websites array" do... | true |
5117ee1358932546bb483da1d9819afff4c026a2 | Ruby | aws/aws-sdk-ruby | /build_tools/changelog.rb | UTF-8 | 6,556 | 2.828125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module BuildTools
# A utility class for managing a CHANGELOG file.
class Changelog
# @option options [String] :path Path to the CHANGELOG.
def initialize(options)
@path = options.fetch(:path)
end
# @return [String]
attr_reader :path
# Inserts an "Unrel... | true |
2d07163902c3ad1ed5f3ad53aebdb216013f0752 | Ruby | LDonoughe/exercism | /ruby/anagram/anagram.rb | UTF-8 | 789 | 3.84375 | 4 | [
"MIT"
] | permissive | =begin
Write your code for the 'Anagram' exercise in this file. Make the tests in
`anagram_test.rb` pass.
To get started with TDD, see the `README.md` file in your
`ruby/anagram` directory.
=end
class Anagram
def initialize(string)
@string = string
end
def match(entries)
hash = Hash.new(0)
@string.... | true |
058ffee28efa214c73c05a2a671b4bc1c8ed0e14 | Ruby | arthurfincham/student-directory | /exercises/2_specific_letter.rb | UTF-8 | 1,291 | 4.09375 | 4 | [] | no_license | # Modify your program to only print the students whose name begins with a specific letter.
students = [
{name: 'Dr. Hannibal Lecter', cohort: :november},
{name: 'Darth Vader', cohort: :november},
{name: 'Nurse Ratched', cohort: :november},
{name: 'Michael Corleone', cohort: :november},
{name: 'Alex DeLarge',... | true |
48bf5ae85f3e5a63aaa397501f56a3004dfad9f3 | Ruby | andychups/ruby | /factorial.rb | UTF-8 | 124 | 3.34375 | 3 | [] | no_license | #!/usr/bin/ruby
def factorial( number )
return number > 1 ? number * factorial( number - 1 ) : 1
end
puts factorial(5)
| true |
eb5924c8c64f941432de76f4e7ef5b9a3c55c697 | Ruby | SalzmanGroup/spree-product-assembly | /app/models/spree/order_inventory_assembly.rb | UTF-8 | 3,475 | 2.9375 | 3 | [] | no_license | module Spree
# This class has basically the same functionality of Spree core OrderInventory
# except that it takes account of bundle parts and properly creates and removes
# inventory unit for each parts of a bundle
class OrderInventoryAssembly
attr_reader :order, :line_item, :product
def initialize(li... | true |
73cffcbd1796db9b5bfd06c5c34819444de635ed | Ruby | BillyDa/ruby_fund | /exercise6.rb | UTF-8 | 256 | 3.984375 | 4 | [] | no_license | puts "Please enter a temperature in Fahrenheit"
temperatureF = gets.chomp.to_i
def temp_conversion(temperatureF)
c = ((temperatureF) - 32) * 5 / 9
convert = "The temperature in Celsius is #{c}"
return convert
end
puts temp_conversion(temperatureF)
| true |
60d260e1bbc9d25756be3ee977a5938a98454032 | Ruby | citygram/etl-me | /etl.rb | UTF-8 | 1,284 | 2.78125 | 3 | [] | no_license | require 'active_support/cache'
require 'faraday'
class ETL
class RequestFailed < StandardError; end
class << self
attr_accessor :cache, :generator, :parser, :collections
end
def self.register(path, *args, &block)
collections << new(path, *args, &block)
end
attr_reader :path, :raw_path
def ini... | true |
afd85b49ea22a45cab0dce80cd15ef76719b2c82 | Ruby | arthurljones/junkrig-calc | /src/sail/svg_drawable.rb | UTF-8 | 4,372 | 2.578125 | 3 | [] | no_license | require "math/transform"
require "math/bounds"
require "math/vector2"
require "svg/node"
module Sail
module SVGDrawable
extend ActiveSupport::Concern
included do
def draw_to_svg(svg, mast, tack_to_partners)
svg.layer("Mast & Sail") do |outer_layer|
outer_layer.layer("Sail") do |sail_... | true |
cbec487907b82b8e542d044e05da5df8cf9f284d | Ruby | SymmetricInDesign/W4D4 | /TDD/spec/tdd_spec.rb | UTF-8 | 2,301 | 3.875 | 4 | [] | no_license | require "tdd"
describe Array do
describe "#my_uniq" do
it "does not raise an error if called on an array" do
expect{[1,2,1,3,3].my_uniq}.not_to raise_error
end
it "properly removes all duplicate elements" do
expect([1,2,1,3,3].my_uniq.sort).to eq([1,2,3])
en... | true |
03f4d3f324f5f4303722ceabf97e5e84dc9c7cb9 | Ruby | nettan20/treetop | /tags/slow_failure_trees/spec/grammar/zero_or_more_spec.rb | UTF-8 | 4,483 | 2.71875 | 3 | [] | no_license | require 'rubygems'
require 'spec'
dir = File.dirname(__FILE__)
require "#{dir}/../spec_helper"
context "Zero-or-more of a terminal symbol" do
setup do
@terminal = TerminalSymbol.new("foo")
@zero_or_more = ZeroOrMore.new(@terminal)
end
specify "returns an empty kind of SequenceSyntaxNode when parsing ... | true |
c2f98fe5e8da45133586839a5c8e17c6f6c38d8a | Ruby | made-line/betsy | /test/models/merchant_test.rb | UTF-8 | 3,438 | 2.703125 | 3 | [] | no_license | require "test_helper"
describe Merchant do
before do
@merchant = merchants(:merchant2)
end
describe "validations" do
it "is valid when all fields are filled" do
result = @merchant.valid?
expect(result).must_equal true
end
it "is invalid without a username" do
@merchant.usernam... | true |
35877e552a64d655d398adf83277f7bcc5059be5 | Ruby | droidlabs/morf | /lib/morf/casters/datetime_caster.rb | UTF-8 | 445 | 2.78125 | 3 | [
"MIT"
] | permissive | class Morf::Casters::DateTimeCaster
def self.cast(value, attr_name, options = {})
if value.is_a?(DateTime)
value
elsif value.is_a?(Time)
value.to_datetime
elsif value.is_a?(String)
begin
DateTime.parse(value)
rescue ArgumentError => e
raise Morf::Errors::CastingErro... | true |
d6c6b034307459f5b7c3c8a397a1f083706aa62b | Ruby | c0nspiracy/advent-of-code-2019 | /day_13/part_2.rb | UTF-8 | 774 | 3.0625 | 3 | [] | no_license | # frozen_string_literal: true
require '../lib/intcode.rb'
memory = File.read('input.txt').chomp.split(',').map(&:to_i)
memory[0] = 2
computer = Intcode.new(memory)
score = 0
ball_direction = 0
ball_location = 0
paddle_location = 0
loop do
break if computer.halted?
x, y, tile_id = computer.run_and_return_output... | true |
3e1c693bb497d0198d0e0f4e47bbeb7507715d79 | Ruby | maynardhartman/array-CRUD-lab-online-web-ft-090919 | /lib/array_crud.rb | UTF-8 | 636 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
test_array = Array.new
end
def create_an_array
test_array = ["test", "help", "last", "maynard"]
end
def add_element_to_end_of_array(array, element)
array << element
end
def add_element_to_start_of_array(array, element)
array.unshift(element)
end
def remove_element_from_end_of_a... | true |
c82804a1740a1c3e7b614cd3ebc5498a83ea92a9 | Ruby | tlxxzj/leetcode | /525. Contiguous Array.rb | UTF-8 | 527 | 3.25 | 3 | [] | no_license | # @param {Integer[]} nums
# @return {Integer}
def find_max_length(nums)
h = {}
diff=0
n = nums.length
ret=0
for i in 0...n
if nums[i]==0
diff -=1
else
diff += 1
end
if h[diff].nil?
h[diff] = [i]
else
h[diff] << i... | true |
904c441cb599879fa4b1bba71bd616b2df243a8c | Ruby | ZABarton/project_euler | /009/009.rb | UTF-8 | 736 | 3.9375 | 4 | [] | no_license | # A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
# a^2 + b^2 = c^2
# For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
# There exists exactly one Pythagorean triplet for which a + b + c = 1000.
# Find the product abc.
# c = a + b - 1000
# c = (a^2 + b^2)^0.5
# a + b - 1000 = (a^2 + b^2)^0.... | true |
74fb94e5569a806af1f6f05309f82fb2a2ffb9c2 | Ruby | RUBYLNIK-training-center/smart-banking | /lib/parsers/currency_parser.rb | UTF-8 | 635 | 2.828125 | 3 | [] | no_license | require 'nokogiri'
require 'faraday'
require 'bigdecimal'
class CurrencyParser
HEADERS = { 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0' }.freeze
attr_reader :url, :doc
def initialize(url:)
@url = url
@doc = parse_html
end
def parse
trs = doc.xpath('//tr... | true |
5aa462c3b50b287e10246457a6a89b50df8ef557 | Ruby | mahdiASC/ruby-music-library-cli-v-000 | /lib/concerns/concerns.rb | UTF-8 | 634 | 2.9375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | module Concerns
module Basics
def initialize(name, second= nil, third =nil)
self.name = name
end
def save
self.class.all<<self
end
end
module Findable
def destroy_all
all.clear
end
def create(name)
temp=new(name)
tem... | true |
45e6a1f2b7d9f2975d71b6b2a68c990d454e75c3 | Ruby | goodnessgraces/Programs | /case.rb | UTF-8 | 281 | 3.96875 | 4 | [] | no_license | puts "give number"
number = gets.chomp
if number == "5"
puts "you entered 5"
elsif number == "6"
puts "you entered 6"
else puts "you neither entered 5 or 6"
end
case number
when "5"
puts "you entered 5"
when "6"
puts "you entered 6"
else
puts "you neither entered 5 or 6"
end | true |
435064240ca0589f350a23b696d5d754e07d5596 | Ruby | mongodb/mongo-ruby-driver | /lib/mongo/srv/result.rb | UTF-8 | 4,358 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# rubocop:todo all
# Copyright (C) 2017-2020 MongoDB Inc.
#
# 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
#
# U... | true |
84eebbd50c85247ee9188d708ddd471832b9374e | Ruby | diosurandito/gbe_m1_02_-_oop_inheritance_polymorphism | /hero.rb | UTF-8 | 572 | 3.828125 | 4 | [] | no_license | require_relative 'person'
class Hero < Person
def initialize(name, hitpoint, attack_damage)
super(name, hitpoint, attack_damage)
@deflect_percentage = 0.8
@healing_skill = 20
end
def take_damage(damage)
if rand < @deflect_percentage
puts "#{@name} deflects the a... | true |
34107d25895b402aa584ed70bbd67981d4e03663 | Ruby | ToQoz/Dockerfiles | /damakanize/damakanize | UTF-8 | 207 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require "amakanize"
result = Amakanize.const_get(ARGV[0]).new(ARGV[1])
if result.respond_to?(:each)
result.each do |r|
STDOUT.puts r.to_s
end
else
STDOUT.puts result.to_s
end
| true |
86026974cab336ff6e5ba24d6bf042b13ac34122 | Ruby | javitocor/Ruby-coding-challenges-The-Odin-Project | /caesarCypher.rb | UTF-8 | 334 | 4.09375 | 4 | [
"MIT"
] | permissive | def caesar_cipher(string, number)
array = string.bytes.map do |x|
if x >= 65 && x <= 90
(((x - 65 + number) % 26) + 65).chr
elsif x >= 97 && x <= 122
(((x - 97 + number) % 26) + 97).chr
else
x.chr
end
end
return array.join('')
end
puts caesar_cipher("What a string!", 5)
# "B... | true |
2370d86cd98bcd2284a121ce2216dc4c4a1a3bc4 | Ruby | kealanheena/makers-bnb | /lib/user.rb | UTF-8 | 2,728 | 2.875 | 3 | [] | no_license | require 'pg'
require 'bcrypt'
class User
attr_reader :username, :email
def initialize(username:, email:, password:, id:, created_at:)
@username = username
@email = email
@password = password
@id = id
@created_at = created_at
end
def self.sign_up(username:, email:, password:)
encr... | true |
2593f134ee8dd86b80498f8d20da69f895c148a6 | Ruby | helenakolberg/functions_lab | /ruby_functions_practice.rb | UTF-8 | 1,030 | 4 | 4 | [] | no_license | def return_10()
return 10
end
def add(num1, num2)
return num1 + num2
end
def subtract(num1, num2)
return num1 - num2
end
def multiply(num_1, num_2)
return num_1 * num_2
end
def divide(num_1, num_2)
return num_1 / num_2
end
def length_of_string(test_string)
return test_string.length
end
de... | true |
f6a5b4eaad5617585412538bb45a72577a5bdf6c | Ruby | thruc/practice_ruby | /base/numeric.rb | UTF-8 | 185 | 3.84375 | 4 | [] | no_license |
# int
i = 100
# float
f = 2.5
puts i
puts f
# floatに変換
puts i.to_f
# classを確認
puts i.class
puts f.class
puts i.to_f.class
# method確認
puts i.methods
puts f.methods | true |
39c67e40768c09b33e2276a90f56dda84d19d29d | Ruby | plinsy/Mer2 | /lib/app.rb | UTF-8 | 2,412 | 2.96875 | 3 | [] | no_license | require 'twitter'
require 'dotenv'
require_relative 'list.rb'
Dotenv.load
@client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
config.access_token = ENV["TWITTER_ACCESS_TOKEN"]
config.acce... | true |
3a657c647332d46ef8aefa08a60822fa6a44349b | Ruby | applideveloper/ruby | /hello3.rb | UTF-8 | 229 | 2.703125 | 3 | [] | no_license | # 変数: データにつけるラベル
# 定数: 変更されないデータにつけるラベル
# 定数は大文字
msg = "hello world"
p msg
ADMIN_EMAIL = "taguchi@gmail.com"
#ADMIN_EMAIL = "hogehoge"
# 定数は変更できない
| true |
0437b9e93564d6dbb62e69f0f8b04b8c722970ce | Ruby | thanhtam22031995/learning | /jul_13/DivisibleSumPairs.rb | UTF-8 | 571 | 3.046875 | 3 | [] | no_license | nk = gets.rstrip.split
n = nk[0].to_i
k = nk[1].to_i
ar = gets.rstrip.split(' ').map(&:to_i)
x = i = 0
while i < n
j = 0
while j < n
if (((ar[j] + ar[i]) % k ) == 0 ) && i != j
x += 1
end
j +=1
end
i +=1
end
puts x/2
#https://www.hackerrank.com/challenges/div... | true |
8d56849037d99c3922351f5872fc0347ed36b9af | Ruby | JupiterLikeThePlanet/little-lims | /app/services/unit_converter.rb | UTF-8 | 1,606 | 2.84375 | 3 | [] | no_license | class UnitConverter
attr_reader :sample_test_report
GRAMS_PER_OZ = 28.349523125 # https://en.wikipedia.org/wiki/Ounce#International_avoirdupois_ounce
UNITS = [
PERCENTAGE = '%'.freeze,
MILLIGRAMS_PER_GRAM = 'mg/g'.freeze,
PARTS_PER_MILLION = 'PPM'.freeze
].freeze
MILLIGRAM_CONVERSION_FACTOR = {... | true |
02a162f7be1bf32493aa4bf8481510b21f5aae34 | Ruby | sesuonap/object_oriented_ruby | /employee.rb | UTF-8 | 1,106 | 4.125 | 4 | [] | no_license |
class Employee
attr_reader :first_name, :salary, :active
attr_writer :first_name, :last_name
def initialize(input_options)
@first_name = input_options[:first_name]
@last_name = input_options[:last_name]
@salary = input_options[:salary]
@active = input_options[:active]
end
def print_inf... | true |
1ba57af23e30f96cc530ba7b3bfb3551b1aa86ee | Ruby | arieldavis22/ruby-oo-inheritance-modules-lab-atlanta-web-021720 | /lib/concerns/findable.rb | UTF-8 | 286 | 2.984375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
module Findable
attr_accessor :name
@@all_names =[]
def initialize(name)
@name
end
def self.all
@@all_names
end
def find_by_name(name)
self.detect {|a| a.name == name}
end
end
Findable.new("Name")
binding.pry | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.