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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9b94d35a6578f4965c7701f0ed8908bffe7f9f9a | Ruby | sergiomauz/Microverse-Coding-Challenges | /Mandatory/033 - Mas Sets Hashes - Maps/AppearsMostTimes.rb | UTF-8 | 532 | 3.78125 | 4 | [
"MIT"
] | permissive | def appears_most_times(array)
h = {}
array.each do |item|
if h.has_key?(item.to_s)
h[item.to_s] += 1
else
h[item.to_s] = 1
end
end
pair_array = h.max_by { |key, value| value }
pair_array[0].to_i
end
puts appears_most_times([1, 2, 3, 1, 5])
# => 1
puts ap... | true |
8f65b06d70e0a5003531b6f0a2215b783004c7e7 | Ruby | ritabc/numbers-to-words | /lib/number_to_words.rb | UTF-8 | 2,424 | 3.96875 | 4 | [
"MIT"
] | permissive | class NumberToWords
def initialize(number)
@number = number
end
def translate()
ones_and_teens = {0 => "", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine", 10 => "ten", 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen',... | true |
25103873cb13ac174c999e0113d99f1bf2b76083 | Ruby | Bluezzy/101 | /101-109complete_attempt/recursion.rb | UTF-8 | 123 | 3.09375 | 3 | [] | no_license | # code wars exercice solution with recursion
def perfect_triangle(n)
return 0 if n == 0
perfect_triangle(n-1) + n
end
| true |
2fd328a2f9f41bdddd11d28e92a19909f1a75e74 | Ruby | JVCanada/nivelamento-aluno | /simulado/02-simulado.rb | UTF-8 | 1,624 | 4.46875 | 4 | [] | no_license | # 2) Defina uma função chamada “negativos_positivos”,
# que deve receber um array de números e que deve retornar outro array com os seguintes 3 números:
# 1. Na primeira posição, o percentual de números do array que são positivos
# 2. Na segunda posição, o percentual de números do array que são zero
# 3. Na última pos... | true |
274d99bbf2a2ea920184bf7d574695767a289b84 | Ruby | mosesogwo/Test-Enumerable | /spec/enumerables_spec.rb | UTF-8 | 4,874 | 3.5 | 4 | [] | no_license | # frozen_string_literal: true
require './lib/enumerable.rb'
describe Enumerable do
let(:arr) { [1, 2, 7, 8, 5] }
let(:n) { arr.length }
describe '#my_each should' do
it 'call the given block once for each element in self' do
my_each_output = ''
block = proc { |num| my_each_output += num.to_s }
... | true |
8ffa9123b74bf7bf0ea5d651eeb56b22d9ccb0f5 | Ruby | hugobarauna/forca | /spec/game_spec.rb | UTF-8 | 4,714 | 3.328125 | 3 | [] | no_license | require "game"
RSpec.describe Game do
let(:word_raffler) { double("word raffler").as_null_object }
subject(:game) { Game.new(word_raffler) }
context "when just created" do
it "has the :initial state" do
expect(game.state).to eq(:initial)
end
end
describe "#ended?" do
it "returns false wh... | true |
334dfa5f15b555165aa875d2d5288e66ea4df707 | Ruby | RossLitzenberger/ruby | /core/struct.rb | UTF-8 | 235 | 2.953125 | 3 | [] | no_license | # class`
Struct.new("Treehouse", :name, :location)
treehouse = Struct::Treehouse.new
treehouse.name = "Treehouse"
treehouse.location = "Treehouse Islands"
puts treehouse.inspect
# that great but we need to get that to the top level | true |
4e037aa046162d271ac5018ec8e8a6ba427e4c6a | Ruby | kvanier2822/skillcrush-project-1 | /ruby_challenges/love_note.rb | UTF-8 | 294 | 3.375 | 3 | [] | no_license | all_notes = [
"Roses are red",
"Violets are blue",
"You are a beef",
"and I love you",
":) <3"
]
total_number_of_notes = all_notes.size
notes_displayed = 0
while (notes_displayed <= total_number_of_notes)
puts all_notes[notes_displayed]
notes_displayed += 1
puts notes_displayed
end
| true |
1738974b646dc9b5c15a3e1e8c72df1b93ec6cda | Ruby | youpy/kisyo | /lib/kisyo/daily.rb | UTF-8 | 1,048 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'open-uri'
module Kisyo
class Daily
CACHE_SIZE = 100
def initialize(location)
@location = location
@cache = Cache.new
end
def at(date)
key = [date.year, date.month, date.day].join(',')
if value = cache.get(key)
return value
end
... | true |
9c2493ae83e4c8bed5e425f6175b9518383af455 | Ruby | dongmy54/model-associate | /lib/tasks/my_data.rake | UTF-8 | 1,585 | 2.859375 | 3 | [] | no_license | namespace :my_data do
task assembly_part: :environment do
p1 = Part.create(:name => "hu")
p2 = Part.create(:name => "bar")
puts "创建了两笔零件资料"
a1 = Assembly.create(:name => "part-1")
a2 = Assembly.create(:name => "part-2")
puts "创建了两笔装配体资料"
p1.assemblies << a1 # 注意这个关联建立的是双向关系
p1.ass... | true |
5a47380da040a5cd92bd9b1bebb77efb1becc4df | Ruby | jamespharaoh/hq-logger | /lib/hq/logger/html-logger.rb | UTF-8 | 4,686 | 2.609375 | 3 | [] | no_license | require "hq/tools/escape"
require "hq/logger/io-logger"
module HQ
class Logger
class HtmlLogger < IoLogger
include Tools::Escape
def valid_modes
[ :normal, :complete ]
end
def output_real content, stuff
if content.is_a? String
out.print \
stuff[:prefix],
"<div class=\"hq-log-simple\">",
es... | true |
e45f72bbeced149eb3279b4cc838fe181d3a4e99 | Ruby | mcsqueeze/jobs | /backend/level1/rental.rb | UTF-8 | 949 | 3.28125 | 3 | [] | no_license | class Rental
attr_reader :id, :car_id, :start_date, :end_date, :distance
def initialize(id, car_id, start_date, end_date, distance)
@id = id
@car_id = car_id
@start_date = start_date
@end_date = end_date
@distance = distance
end
def self.all
data = Input.new.inputrentals
@rentals =... | true |
0e8a1cf46a337aeeed9c635550cba0133511e9ba | Ruby | rdiar0991/Gojek-web-app-Orders-Drivers-Services | /lib/location_finder.rb | UTF-8 | 380 | 2.578125 | 3 | [] | no_license | require "google_maps_service"
module LocationFinder
def get_coord(location)
return nil if location.nil? || location.empty?
gmaps = GoogleMapsService::Client.new(key: 'AIzaSyAT3fcxh_TKujSW6d6fP9cUtrexk0eEvAE')
results = gmaps.geocode(location)
if results.empty? || results.length == 0
return nil
... | true |
d81f6c9d6380cf680ab29c24ba7bfe7c76e345d8 | Ruby | michaelkirk/flash_flow | /lib/flash_flow/lock/github.rb | UTF-8 | 1,954 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'octokit'
module FlashFlow
module Lock
class Github
attr_reader :config
private :config
def initialize(config)
@config = config
verify_params!
initialize_connection!
end
def with_lock(&block)
if issue_open?
raise Lock::Error.new(... | true |
a4ce03062535c22322002d0b81763e1f5c4cc1ac | Ruby | shadabahmed/leetcode-problems | /0277-find-the-celebrity.rb | UTF-8 | 1,354 | 3.90625 | 4 | [] | no_license | # https://leetcode.com/problems/find-the-celebrity/
def knows(a, b)
{[0,1] => true, [1,0] => true, [0,2] => true}[[a,b]]
end
# 0 knows 1
# 0 knows 2; 1 knows 0
# 1 does not know 2; 2 does not know 0
# 2 does not know 1.
def find_celebrity(n)
current = 0
while true
next_person = (current + 1) % n
while n... | true |
e600c3d8a0c3edc10c797fadee1f894766d87763 | Ruby | gtmtechltd/cryptostat | /lib/stat_bscwallet.rb | UTF-8 | 2,483 | 2.640625 | 3 | [] | no_license | require_relative "./utils.rb"
require 'net/http'
require 'uri'
require 'json'
class StatBscwallet
@@lasttime = Time.now.to_i
def self.get_response api_key, wallet_address
uri = URI.parse("https://graphql.bitquery.io/")
header = {'Content-Type': 'application/json', 'X-API-KEY': api_key}
query = "{
... | true |
9c09f83f1b2008ed8e817cb489f898168be43cf8 | Ruby | Ronan-deGuernisac/RachelMinto-learn_to_program_cp | /arrays/sorted_words.rb | UTF-8 | 153 | 3.75 | 4 | [] | no_license | array = []
puts "Put in as many words as you want."
words = gets.chomp
while words != ""
array.push(words)
words = gets.chomp
end
puts array.sort
| true |
7ac796a125d9c941496f9102a67430a5cb527796 | Ruby | AmandaLemmons/linked_list | /test/list_test.rb | UTF-8 | 4,269 | 3.296875 | 3 | [] | no_license | require 'minitest/autorun'
require './lib/list'
require './lib/node'
require 'pry'
describe List do
let(:list) { List.new }
describe "#new_list" do
let(:list) {List.new}
it "should build an empty list" do
list.head.must_equal nil
list.tail.must_equal nil
list.elements.must_equal nil
... | true |
610473b3620fa162df767169199dbf2238a9e33c | Ruby | minchana/Minchana | /backend/Ruby/Test5.rb | UTF-8 | 333 | 2.78125 | 3 | [] | no_license | class Anamil
def dog_sound
puts "Woof Woof"
end
def lion_sound
puts "Roar"
end
def rabbit_sound
puts "squeak"
end
def elephant_sound
puts "Trumps"
end
end
class Dog <Anamil
end
# class SubAnimal <Anamil
# end
# a=SubAnimal.new
# a.dog_sound
# a.lion_sound
# a.rabbit_sound
# a.elephant_sound
a=Dog.new
... | true |
d02baa805b04f8f9e19bf7119a4baba9cd539b79 | Ruby | delacruzjames/ProjectEuler | /ruby/largest_prime_factor.rb | UTF-8 | 1,077 | 3.6875 | 4 | [] | no_license | # PROBLEM
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
require 'concurrent'
require 'minitest/autorun'
require 'pry'
class LargestPrimeFactorTest < Minitest::Test
def test_get_factor_of_24
# skip
assert_equal 3, LargestPrimeFactor.largest_p... | true |
68daea9c4d6f5c1236dcb4794a06be1897105ca2 | Ruby | aranagi/1zinsei | /1zinsei.rb | UTF-8 | 1,510 | 2.671875 | 3 | [] | no_license | # coding: utf-8
#フルパスをロードパスに追加
fullpath=File.dirname(File.expand_path(__FILE__))
$:.unshift fullpath
#よみこむ
require 'user_stream'
require 'twitter'
#tokenの設定
require './token.rb'
UserStream.configure do |config|
config.consumer_key = Consumer_key
config.consumer_secret = Consumer_secret
config.oauth_token = Oauth... | true |
3dc56452c618387ae2f414a5b4b19b5aed93ebbe | Ruby | aramsalimi91/Payback | /spec/models/group_spec.rb | UTF-8 | 2,185 | 2.609375 | 3 | [] | no_license | # == Schema Information
#
# Table name: groups
#
# id :integer not null, primary key
# gid :string(255)
# title :string(255)
# password_digest :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# owner_id :inte... | true |
cab70b837bf4d86dd2e53593c780bfdd8ea0e30f | Ruby | gigorok/rspecast | /lib/rspecast/parser.rb | UTF-8 | 2,620 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Rspecast
class Parser
@@cache = {}
attr_accessor :logger, :file_path
def initialize(file_path:, line_no:, recache: true)
@file_path = file_path
@line_no = line_no
@recache = recache
end
def to_ast
unless @recache
if @@cache[@... | true |
249ba4e1f1817ee563a4552944e1ac7fa0d43927 | Ruby | DrkCloudStrife/drkstrife-site | /app/objects/articles.rb | UTF-8 | 850 | 2.875 | 3 | [] | no_license | # Normally this would hit an ActiveRecord model to fetch articles. However, I'm
# challenging myself by not using a database, this iteration will use JSON
# files as a base, I might consider changing it to YAML. I just want to provide
# alternatives to using a database model.
class Articles
ARTICLE_DATA_PATH = "arti... | true |
3b15dab9a10299862650d2cc02a77a1898e61310 | Ruby | KevSeenan/PDA | /static_and_dynamic_testing/card_game.rb | UTF-8 | 708 | 3.796875 | 4 | [] | no_license | ### Testing task 2 code:
# Carry out dynamic testing on the code below.
# Correct the errors below that you spotted in task 1.
class CardGame
def initialize(suit, value) #This was also missing from static test file
@suit = suit
@value = value;
end
def check_for_ace(card)
if card_value == 1 #== a... | true |
5432caf68e3c0091dadef29b20ab910a8e70d9da | Ruby | kyamaguchi/tsundoku | /app/values/normalizer.rb | UTF-8 | 940 | 3.421875 | 3 | [] | no_license | class Normalizer
def self.normalize(str)
halfsize(str).gsub(/[\s ]+/,'')
end
def self.halfsize(str)
str.tr('0-9a-zA-Z', '0-9a-zA-Z')
end
def self.extract_categories(str)
categories = []
[
['(', ')'],
['<', '>'],
['[', ']'],
['(', ')'],
['[', ']'],
['【',... | true |
c5d62beacde9d57e7d2538c2ffd0dbabe18da078 | Ruby | luke-jones-1/chitter-challenge | /lib/chitter.rb | UTF-8 | 1,056 | 2.78125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'database_connection'
require 'user'
class Chitter
def self.sign_up(username:, email:, password:)
if email_used?(email)
'email used'
elsif username_used?(username)
'username used'
else
User.create(username: username, email: email, password... | true |
d391836133885e29ea90870d4d4f489524da857e | Ruby | OhCoder/designpatterns-ruby | /strategy/warm.rb | UTF-8 | 101 | 2.765625 | 3 | [
"MIT"
] | permissive | require_relative 'weather'
class Warm <Weather
def move
puts "Ok, let's go to swim"
end
end
| true |
4b437e548cd243ba320f818564d7fbbfb5440d26 | Ruby | xiaoningyb/tvshow | /app/models/crawler_info.rb | UTF-8 | 1,550 | 2.53125 | 3 | [] | no_license | # -*- coding: utf-8 -*-
class CrawlerInfo < ActiveRecord::Base
attr_accessible :begin_time, :crawl_link_counter, :crawl_page_counter, :end_time, :group_counter, :new_group_counter,
:new_program_counter, :new_station_counter, :program_counter, :station_counter, :current_crawl_station,
... | true |
193a70665bf089fc0a09e05b0a05d594ef744919 | Ruby | leungleungtest1/assignmets_for_lesson2 | /oop_blackjack.rb | UTF-8 | 5,595 | 3.484375 | 3 | [] | no_license | # There are 1 deck, 52 cards, 2 player
# Deck is an array of 52 cards(objects)
class Deck
attr_accessor :cards_d
def initialize
@cards_d = []
no_cards = ['S','H','D','C'].product(['2','3','4','5','6','7','8','9','10','J','Q','K','A'])
no_cards.each{|array| @cards_d<<Card.new(array[0],array[1])}
... | true |
8fea6633969b272f39fd1855619abb02f43ee309 | Ruby | alexdean/app_status | /app/models/app_status/check_item.rb | UTF-8 | 1,258 | 2.8125 | 3 | [
"MIT"
] | permissive | module AppStatus
class CheckItem
attr_reader :name, :status, :status_code, :details, :ms
attr_accessor :proc, :description
def initialize(name, include_description: false)
@name = name
@proc = nil
@description = ''
reset
end
def reset
@result = {}
end
def ... | true |
ada0e8390253fd404b673cded9b3da7c0e78cde4 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grade-school/b6d78e4a251241c1863d8f682b9fd744.rb | UTF-8 | 310 | 3.25 | 3 | [] | no_license | class School
attr_accessor :grades
def initialize
@grades = {}
end
def grade(grade)
grades[grade] || []
end
def db
@grades
end
def add(name, grade)
grades[grade] ||= []
grades[grade].push(name)
end
def sort
Hash[@grades.map{ |k,v| [k, v.sort] }.sort]
end
end
| true |
14624772b3cab87fe0972903d815aa3e30db3aeb | Ruby | LewisMac/blackjack | /cards.rb | UTF-8 | 240 | 2.796875 | 3 | [] | no_license | class Cards
attr_reader :value
def initialize()
# @value = value
end
def hash
@cards[1] = 2
@cards[2] = 4
@cards[3] = 6
@cards[4] = 8
end
# attr_reader :value
# def initialize(value)
# @value = value
# end
end | true |
abcd3556ae660efa5e674a92355772369aa8526e | Ruby | keiteio/ShootingGame | /scripts/win32utils.rb | UTF-8 | 632 | 2.78125 | 3 | [] | no_license | #==============================================================================
# ■ Win32APIHelpers
#------------------------------------------------------------------------------
# Win32APIを使ったヘルパーメッソッドを提供するモジュール
#==============================================================================
module Win32APIHelpers
... | true |
c140d9669b22a9d8eade9f7ed05d0e0b9aa4001c | Ruby | heathercreighton/fall17-ruby-day6 | /fighter/spec/fighter_spec.rb | UTF-8 | 824 | 3.265625 | 3 | [] | no_license | require "../lib/fighter"
RSpec.describe Fighter do
let(:fighter1){Fighter.new(name: "Chun Li", health: 100, power: 50)}
let(:fighter2){Fighter.new(name: "Ryu", health: 100, power: 50)}
it '.new creates a new fighter' do
expect(fighter1).to be_an_instance_of Fighter
end
it '#name returns fighter name' do
... | true |
ec28ec25adebaa41058e455c40386c823357759c | Ruby | sroop/Battleships | /lib/shipbuilder.rb | UTF-8 | 1,746 | 2.9375 | 3 | [] | no_license | module ShipBuilder
def register_shot(coordinates)
@grid[coordinates].content.hit!
end
def random_coordinate_generator
letter = ("A".."J").to_a.sample
number = (1..10).to_a.sample.to_s
random_coordinate = letter + number
return random_coordinate
end
def second_coordinate
first_spot = random_coordina... | true |
7168e0c93d1d684240dc85c57afda0fdbe56f46c | Ruby | zeusintuivo/bin | /asciichart | UTF-8 | 362 | 3.140625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
decimal = ARGV[0] && ARGV[0] == "-d"
hex = !decimal
label_format = hex ? "%02x " : "%2d "
xlabels = (0...16).map {|c| label_format % c } * ''
ylabels = (0...16).map {|c| label_format % (c*16) }
puts " " + xlabels
(1...16).each do |base|
print ylabels[base]
16.times do |offset|
print "... | true |
75095607db57e99ae5fbf2f49f69a0272201782e | Ruby | aahmad94/algorithm_projects | /01_dynamic_array/lib/static_array.rb | UTF-8 | 425 | 3.96875 | 4 | [] | no_license | # This class just dumbs down a regular Array to be statically sized.
class StaticArray
def initialize(length)
@store = Array.new(length)
end
# O(1)
def [](index)
self.store[index]
end
# O(1)
def []=(index, value)
self.store[index] = value
end
protected
attr_accessor :store
end
# stat... | true |
d60d5eaed17738a26b75c1502198c5890e4f4bda | Ruby | hazimIskandar/rawMaterial | /app/models/raw_transaction.rb | UTF-8 | 770 | 2.640625 | 3 | [] | no_license | class RawTransaction < ActiveRecord::Base
belongs_to :material
before_save :set_price
after_save :update_current_stock
after_destroy :update_delete_stock
validates_presence_of :t_quantity, :t_total_price
def set_price
self.t_price_unit = self.t_total_price / self.t_quantity
end
def update_current_stock
if... | true |
00514741768fc005814f36fd96b4a1932ee7bda8 | Ruby | crineu/gallery | /images_recursion/recursion.rb | UTF-8 | 1,023 | 3.078125 | 3 | [] | no_license | # black magic from web, so we don't need gems to read sizes, etc
def size(image_filename)
if '.png' == File.extname(image_filename)
return IO.read(image_filename)[0x10..0x18].unpack('NN')
elsif '.gif' == File.extname(image_filename)
return IO.read(image_filename)[6..10].unpack('SS')
else
return [10, 10]
end
... | true |
13c566671950c9c65f877e0406a671f6b68c842c | Ruby | matthewrudy/moving-people-safely | /app/services/metrics/exporter.rb | UTF-8 | 3,353 | 2.578125 | 3 | [] | no_license | module Metrics
class Exporter
def initialize(calculator, options = {})
@calculator = calculator
@api_config = Rails.application.secrets[:geckoboard]
@logger = options.fetch(:logger, Rails.logger)
end
def call
log_disabled && return unless api_key
logger.info 'Sending updated... | true |
b5eafcd4b5a43b70a4ee0908ea075588c50ca316 | Ruby | Andria177/morpion_2304 | /app.rb | UTF-8 | 2,925 | 3.9375 | 4 | [] | no_license |
class Player #A dispatcher dans des fichiers par classe plus tard
attr_accessor :name, :choice
def initialize(name, choice, board)
@name = name
@choice = choice
@board = board
end
def move(cell)
@board.update_cell(cell, self.choice)
end
def victory?
wins = [[0, 1, 2], [3, 4, 5], [6, ... | true |
0771e1de14b3cec84eb55bbd678efe93a81113a6 | Ruby | VUE/VUE | /vue_releases/installer_modify.rb | UTF-8 | 688 | 2.984375 | 3 | [] | no_license | class InstallerModify
attr :file, :version
@properties = {}
@max_lines = 0
#Takes a file and loads the properties in that file
def initialize(file, version)
@file = file
@version = version
@properties = {}
index = 0
@max_lines = 0
IO.foreach(file) do |line|
@properties[index] = line
index +=1
end
@max... | true |
484c9f1838d42e819512e27396f0a0e9ca693547 | Ruby | MikeConner/machovy_rails | /lib/promotion_strategy_factory.rb | UTF-8 | 1,569 | 3 | 3 | [] | no_license | require 'singleton'
require 'fixed_expiration_strategy'
#
# CHARTER
# Factory for promotion strategies. Trying to encode all the complex logic of widely varying promotion types
# (e.g., 2-for-1, time-limited, 1-max, min-max, etc.) in the Promotion object would lead to 5 or 6 new fields with very
# complex interactio... | true |
ce7b8fe55c7266c21fa712bc4a75a262639aadb8 | Ruby | MarkQM/BedBug | /app/helpers/rental_properties_helper.rb | UTF-8 | 1,258 | 2.71875 | 3 | [] | no_license | require 'open-uri'
require 'json'
module RentalPropertiesHelper
def geocode(address)
uri = URI.parse(URI.escape("https://maps.googleapis.com/maps/api/geocode/json?address=#{address}"))
uri.open do |f|
h = JSON.parse(f.read)
if h['status'] == 'OK' and h['results'].length > 0
lat = h['resul... | true |
e3ef3cdc5dfe9934d8f986e4a47e159e2c4c40c3 | Ruby | Mtmackenzie/ls101 | /101.4/method_practice/method_practice7.rb | UTF-8 | 1,370 | 3.984375 | 4 | [] | no_license | # Create a hash that expresses the frequency with which each letter occurs in this string:
statement = "The Flintstones Rock"
# { "F"=>1, "R"=>1, "T"=>1, "c"=>1, "e"=>2, ... }
# MY SOLUTION
# array = []
# array << statement.split(//)
# array = array.flatten
# array.keep_if {|character| character != ' '}
# def s... | true |
3a9ed50c606550f3eb18e7ccd052053eb1bf0e95 | Ruby | RobinWagner/LaunchSchool | /programming_and_back-end_development/programming_foundations/AppAcademyProblems/exercise6.rb | UTF-8 | 191 | 3.390625 | 3 | [] | no_license | def count_vowels(string)
string.count('aeiou')
end
# Test cases
p count_vowels('abcd') == 1
p count_vowels('color') == 2
p count_vowels('colour') == 3
p count_vowels('cecilia') == 4
| true |
771a090c9729d810e2a05e05354c419bd9ed043d | Ruby | acjshapiro/rbgolf | /hole4.rb | UTF-8 | 241 | 3.578125 | 4 | [] | no_license | def mult
puts "enter a number"
n = gets.to_i
puts "enter a maximum"
m = gets.to_i
a = []
i = 0
while i < m
i += 1
a << i
end
a.each do |x|
if x % n == 0
puts x
else
end
end
end
mult
#119 char
| true |
51b493794dd543db394ba0bd2bada40c2eff61fd | Ruby | ntodd/adva_cms | /engines/theme_support/app/models/theme/file.rb | UTF-8 | 2,066 | 2.640625 | 3 | [
"MIT"
] | permissive | class Theme
class File < Path
class << self
def build(theme, path, data = nil)
[Theme::Other, Theme::Asset, Theme::Template].each do |klass|
return klass.new(theme, path, data) if klass.valid?(path)
end
# TODO raise something more meaningful
raise "Can't build file ... | true |
4a4203d922ec58f03046e1c576db787a7bb05657 | Ruby | keoki33/collections_practice_vol_2-london-web-career-031119 | /collections_practice.rb | UTF-8 | 1,820 | 3.640625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
require 'pry'
def begins_with_r(list)
list.all? do |word|
word[0].include? "r"
end
end
def contain_a(list)
list.select do |word|
word.include? "a"
end
end
def first_wa(list)
list.find do |word|
word[0].include? "w" and word[1].include? "a"
end
end
def remove_non_strings(list)
list.delete_if do |word|
... | true |
6edab831a09293cb5e06de2be79d748f97d1d587 | Ruby | pierre-pat/ruby-processing | /colored_points.rb | UTF-8 | 1,926 | 3.421875 | 3 | [] | no_license | require 'ruby-processing'
class Centroid
attr_accessor :vector, :size, :color
def initialize vector, size, color
@vector, @size, @color = vector, size, color
end
end
class ColoredPoints < Processing::App
def setup
size 500, 500
smooth
centroid_size = 10
@points_size = 5
@centroids =... | true |
13028d2495a627253caf113c816dde0340dd235d | Ruby | lgentaz/THP_J7_Ruby1 | /exo_16.rb | UTF-8 | 241 | 3.375 | 3 | [] | no_license | puts "Entrez votre année de naissance:"
print "> "
annee_naissance = gets.chomp.to_i
age = 2020 - annee_naissance + 1
number = 0
(age).times do
puts "Il y a #{age - number - 1} an(s), tu avais #{number} an(s)."
number = number + 1
end
| true |
61d15bd439f67c83d103d36ef15597d88e910ad1 | Ruby | poserdal/hot_mess | /array.rb | UTF-8 | 747 | 4.15625 | 4 | [] | no_license | fruits = ["Apples", "Oranges", "Bananas"]
people = ['Mattan', 'Chris', 'Lee']
things = ["Dogs", 55, true, people]
numbers = (1..10).to_a # "to_a = to array" => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
puts "These are the things: #{things}"
puts "This is thing #1: #{things[0]}" # Don't forget to start at 0
puts "This is the la... | true |
aaf2525bc7d2a50450cf1a1bbbd555ca48ad847d | Ruby | kudryavchik/wallet-core | /codegen/bin/cointests | UTF-8 | 1,697 | 2.984375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Sript for creating/updating CoinType unit tests, based on the coins.json file
# It is intended as a one-time or occasional generation, not every time! (that way the tests would have zero added value)
# Usage: codegen/bin/cointests
# Files are generated to: tests/<Coin>/TWCoinTypeTests.cpp
requir... | true |
2c61d41a1e23b38675b600927c4c1ba75ca6636b | Ruby | dagpan/active-record-practice-playlister-static-generator-lab-nyc04-seng-ft-012720 | /app/models/song.rb | UTF-8 | 173 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
class Song < ActiveRecord::Base
belongs_to :artist
belongs_to :genre
def to_slug
self.name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
end
| true |
77e9ac805b9a74bf118560a5b066391a1af96e04 | Ruby | lapeterson01/go_fish | /app/models/go_fish_game.rb | UTF-8 | 118 | 2.546875 | 3 | [] | no_license | class GoFishGame
attr_reader :deck, :players
def initialize
@deck = CardDeck.new
@players = {}
end
end
| true |
62037f9c96d4513835ae6614903ebd8097ddd70f | Ruby | ntnga/hoc-ruby | /Ruby/Chuong 9/demo_general_specific.rb | UTF-8 | 344 | 3.515625 | 4 | [] | no_license | class NhacCu
def initialize
raise 'Nhac Cu Class !!'
end
def choi_nhac
raise 'choi nhac abstract method!!'
end
end
class Guitar < NhacCu
def initialize
@so_day = 6
end
def choi_nhac
puts "Người choi tạo ra âm thanh bằng cách gảy lên #{@so_day} dây đàn"
end
end
nga = Guitar.new
nga.... | true |
2bf1a4b5504403f8ec75d616bcad91fa486eb921 | Ruby | rchampourlier/Bookmailist | /spec/lib/link_extractor_spec.rb | UTF-8 | 2,192 | 2.921875 | 3 | [] | no_license | describe LinkExtractor do
describe LinkExtractor::HTML do
describe "from" do
before(:all) do
@html_first_link_title = "the first link title"
@html_first_link = "http://www.first.com"
@html_second_link_title = "the second link title"
@html_second_link = "http://www.second.com"
@html_1_link ... | true |
f889e3fac6fcd204af4328fc215e0f2e50ef5072 | Ruby | Origen-SDK/origen_testers | /spec/decompiler/topmost_methods.rb | UTF-8 | 6,554 | 2.546875 | 3 | [
"MIT"
] | permissive | # The main methods present on the Decompiler class.
# Unlike the tests ./decompiler_api.rb, these are actually running going for
# validation/correctness, not merely making sure they're there.
# These are the most advertised, key, methods of the decompiler. That is, if
# nothing else, make sure these methods work as e... | true |
785bc826fac05e07d9df7c9d7e56ca9c91969480 | Ruby | asane/twml-quickstart-heroku | /web.rb | UTF-8 | 1,379 | 2.578125 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require 'sinatra'
require 'haml'
require "sinatra/reloader" if development?
before do
content_type 'xml'
end
get '/' do
content_type 'html'
haml :'index', {:layout => false}
end
get '/hello-monkey' do
haml :'hello-monkey'
end
get '/hello-monkey-handle-key' do
redirect '/' unless %W... | true |
6c1dc81f889cbe88bf2a575c88dcd87f2b208a06 | Ruby | walidwahed/ls | /130-ruby-foundations/lesson_1/todo.rb | UTF-8 | 4,827 | 4.28125 | 4 | [] | no_license | # This class represents a todo item and its associated
# data: name and description. There's also a "done"
# flag to show whether this todo item is done.
class Todo
DONE_MARKER = 'X'
UNDONE_MARKER = ' '
attr_accessor :title, :description, :done
def initialize(title, description='')
@title = title
@d... | true |
bb4a6d5ff9b489244aa5bdfcfaea966ea2701e3e | Ruby | jlbeans/Mastermind | /main.rb | UTF-8 | 559 | 3.25 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'game'
# This class starts/ends the game
class Main
attr_reader :game
def initialize
@game = Game.new
end
def start_game
game.welcome
game.choose_which_player
new_game
end
def new_game
puts "Would you like to play again? \n
Y/N"
... | true |
1448f420110feba6017f449816c0a70a0f8e89c5 | Ruby | afiore/extraloop | /spec/iterative_scraper_spec.rb | UTF-8 | 4,911 | 2.53125 | 3 | [] | no_license | require 'helpers/spec_helper'
include Helpers::Scrapers
describe IterativeScraper do
before(:each) do
@fixture_doc ||= proc {
file = File.open("fixtures/doc.html", "r")
file_content = file.read
file.close
file_content
}.call
end
describe "#initialize" do
subject { IterativeSc... | true |
57e08a53b7b7651f182dce21a6f2c230f55e5705 | Ruby | eallsopp/RB_challenges | /Easy2/2/scrabble_score.rb | UTF-8 | 2,499 | 4.09375 | 4 | [] | no_license | =begin
Scrabble Score
Write a program that, given a word, computes the scrabble score for that word.
Letter Values
You'll need these:
Letter Value
A, E, I, O, U, L, N, R, S, T 1
D, G 2
B, C, M, P 3
F, H, V, W, Y ... | true |
74aef6d9694b38d0ebf4ac1a9fa2e02098b67f49 | Ruby | cdscally/Prabu | /spec/player_spec.rb | UTF-8 | 287 | 2.90625 | 3 | [] | no_license | require 'player'
describe Player do
it 'returns its name' do
player = Player.new('Prabu')
expect(player.name).to eq('Prabu')
end
it 'reduces hp when attacked' do
player = Player.new('Colin')
expect { player.reduce_hp }.to change { player.hp }.by(-10)
end
end
| true |
662cde525106ad2285171e903429f7fb14b776eb | Ruby | durhamka/temp-monitor-kata | /temp_spread_finder.rb | UTF-8 | 311 | 3.21875 | 3 | [] | no_license | class TempSpreadFinder
attr_reader :data
def initialize(data)
@data = data
end
def temp_spread
max_temp - min_temp
end
private
def columns
data.split
end
def min_temp
columns[2].to_i
end
def max_temp
columns[1].to_i
end
def day
columns[0].to_i
end
end
| true |
e65862e4246c8aff4e454b8c530ad7fab8d0e99c | Ruby | garybunofsky/ruby-the-hard-way | /ex19.rb | UTF-8 | 1,098 | 4.5625 | 5 | [] | no_license | # defines the function cheese_and_crackers with two arguments
def cheese_and_crackers(cheese_count, boxes_of_crackers)
puts "You have #{cheese_count} cheeses!"
puts "You have #{boxes_of_crackers} boxes of crakers!"
puts "Man that's enough for a party!"
puts "Get a blanket.\n"
end
puts "We can just give the fu... | true |
26a95b78652bd2bd160b96a7058129e4cffe0695 | Ruby | albertbahia/wdi_june_2014 | /w02/d04/najee_gardner/selector/lib/selector.rb | UTF-8 | 135 | 3.3125 | 3 | [] | no_license | def selector(limit)
div_3_5 = (1...limit).select {|num| num % 3 == 0 || num % 5 == 0}
div_3_5.inject(0) {|sum, num| sum + num}
end
| true |
1a53433f0341c9d8c16e56d93a0cbb0346de9f12 | Ruby | thib123/TPJ | /Notes/Ruby/sample_code/ex1068.rb | UTF-8 | 265 | 2.859375 | 3 | [
"MIT"
] | permissive | # Sample code from Programing Ruby, page 509
sprintf("%d %04x", 123, 123)
sprintf("%08b '%4s'", 123, 123)
sprintf("%1$*2$s %2$d %1$s", "hello", 8)
sprintf("%1$*2$s %2$d", "hello", -8)
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23)
| true |
19e89698cf3c6635e86054ee88e9552fa02edc41 | Ruby | BogdanGermanchuk/rubytut | /lesson4/ex4-4.rb | UTF-8 | 1,334 | 3.828125 | 4 | [] | no_license |
# moneta = [
# "орел",
# "решка"
# ]
# puts "Ваша сторона монеты"
# puts
# puts moneta.sample
# encoding: utf-8
# Сгенерим случайное число от 0 до 1 методом rand
# # В качестве параметра этому методу передаём целое число, на единицу большее максимального
# if rand(2) == 1
# puts 'Выпала решка'
# end
# if rand(1... | true |
a3fa2869c61371e0aa0d061c0cf59a3eabdd7678 | Ruby | iangibson807/ruby_exercises | /ruby_exercises/conditionals/exercise_5c.rb | UTF-8 | 256 | 3.90625 | 4 | [] | no_license | def alternative_case_method(x)
case
when 0..50
puts "#{x} is between 0 and 50"
when 51..100
puts "#{x} is between 51 and 100"
else
puts "#{x} out of range"
end
end
puts "enter a number between 0 and 100"
x = gets.chomp.to_i
alternative_case_method(x) | true |
0285bf48f9579a3b0ad6a3c9d31dcdde72be04b1 | Ruby | walidwahed/ls | /exercises/101-109_small_problems/medium2/10-sum_square.rb | UTF-8 | 604 | 4.5 | 4 | [] | no_license | # Sum Square - Square Sum
# Write a method that computes the difference between the square of the sum of the first n positive integers and the sum of the squares of the first n positive integers.
# Examples:
def sum_square_difference(n)
n_integers = (1..n).to_a
square_of_sum = n_integers.inject(:+)**2
sum_of_s... | true |
992deb3ed32e25bb5edb01e5040c472dc237c874 | Ruby | upfluence/rbutils | /lib/upfluence/logger.rb | UTF-8 | 1,283 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'logger'
module Upfluence
class Logger < Logger
class Formatter < Logger::Formatter
TIME_FORMAT = '%y%m%d %H:%M:%S'.freeze
LOG_FORMAT = "[%s %s %s] %s\n".freeze
def initialize(extra = 0)
@extra = extra
end
def call(severity, tstamp, _progname, msg)
LOG_FORM... | true |
041c10a3e82e88a22ac49399f2db8581092f03f7 | Ruby | seano424/squidy | /db/seeds.rb | UTF-8 | 2,545 | 2.71875 | 3 | [] | no_license | require 'faker'
# 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 rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the ... | true |
daca8d171839b5e7e8214a0ff5bd82c318b597ce | Ruby | c1iff/na_translate | /spec/transcribe_spec.rb | UTF-8 | 215 | 2.515625 | 3 | [] | no_license | require('rspec')
require('transcribe')
describe('transcribe') do
it("takes a string sequence of amion acids and translates to protein sequence") do
expect(("atgcatgcaaaa").transcribe).to eq('MHAK')
end
end
| true |
17b05f6e2991a74684bf6285c07823c52d335294 | Ruby | Jonjoe/calendar-app | /app/models/event.rb | UTF-8 | 680 | 3.1875 | 3 | [] | no_license | class Event < ApplicationRecord
# Class Methods
class << self
# Returns an ARRAY of INTEGERS containing free slots.
def days_availability(day)
return Event.where(day:day).pluck(:slot)
end
# Returns INTEGER counting days in current month.
def days_in_current_month
current_month = Time.now.month
cu... | true |
0fb135bdd069c9af2bbe8a5e09a253104ccc93f3 | Ruby | luismojena/neutroRuby | /neutrosophy/factory.rb | UTF-8 | 1,102 | 3.140625 | 3 | [] | no_license | class SVNNumberFactory
def self.random_svn
SVNNumber.new(rand, rand, rand)
end
def self.random_array_of_svn(number_of_elements)
raise ArgumentError, 'value must be an integer number' unless number_of_elements.is_a? Integer
array = []
0.upto(number_of_elements) {array << self.random_svn}
arra... | true |
1cc992143bb18a572207810bc6abf200d7c7b40c | Ruby | jjsanchezrodriguez/IronhackExercises | /Week2/2015-10-22/sinatra-blog/lib/post.rb | UTF-8 | 279 | 2.84375 | 3 | [] | no_license | require 'date'
class Post
attr_reader :title, :date, :text, :author, :category
attr_accessor :pid
def initialize(title, text, author, category)
@pid = nil
@title = title
@date = Time.now
@text = text
@author = author
@category = category
end
end
| true |
43582a14b1babe11f51940961700371d65412569 | Ruby | Matic0B/infrastructure | /controller/lib/linux/env.rb | UTF-8 | 707 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | class Env
class << self
def override
@override ||= {}
end
def get(key, index=0)
raw = override[key.upcase] || ENV[key.upcase]
if raw != nil && !raw.empty? && raw != "null"
values = raw.split(",") rescue []
if index >= 0 && index < values.size
values[index]
else
values
end
... | true |
dcee4a5acb984eedc09a1c24704fcd130b3da6ad | Ruby | namakesugi/privacy_mask_tools | /lib/privacy_mask_tools/email_matcher.rb | UTF-8 | 2,891 | 2.8125 | 3 | [
"MIT"
] | permissive | # coding: utf-8
# Email判定用モジュール
module PrivacyMaskTools::EmailMatcher
# RFC5322形式に近いメールアドレスが存在するかチェックします
# @param [String] 探索対象文字列
# @return [Boolean]
def has_rfc_email?(text)
!text.match(make_rfc_regexp).nil?
end
# RFC5322形式に近いメールアドレスを抽出します
# @param [String] 探索対象文字列
# @return [Array]
def pick_... | true |
a62b92190b7ff3db303b6c17a5407fa23a2ab1e0 | Ruby | mraaroncruz/build-your-own-language-example | /ch3/interpreter.rb | UTF-8 | 1,767 | 2.9375 | 3 | [] | no_license | require "json"
require "./ch3/lexer"
require "./ch3/parser"
module NLPTrainer
module Rasa
class Interpreter
def initialize(code)
@code = code
end
def print
tokens = Lexer.lex(@code)
ast = Parser.parse(tokens)
intents = interpret(ast)
full = wrap(intents)... | true |
fa7bc6606dd3b1d8f76a5914667ebfbd48e0fcc7 | Ruby | jevargasv/CodeWars-Coding-Challenges | /CodeWars/Challenges/Growth_of_a_Population/solution.rb | UTF-8 | 343 | 3.65625 | 4 | [] | no_license | # Growth of a population
def nb_year(p0, percent, aug, p)
age = 0
total = p0
while total < p
age += 1
total += (total * ((percent.to_f)/100)).to_i + aug
puts total
end
return age
end
nb_year(1500, 5, 100, 5000)
nb_year(1500000, 2.5, 10000, 2000000)
nb_year(1500000... | true |
71baec7ef10761788a82127fd011467418d303e1 | Ruby | schoi0115/phase-4-rails-and-active-record-lab | /app/models/student.rb | UTF-8 | 232 | 2.6875 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Student < ApplicationRecord
def to_s
# Student.create(first_name: Dwayne, last_name: Johnson)
# "#{self.first.first_name} #{self.first.last_name}"
"#{self.first_name} #{self.last_name}"
end
end
| true |
d286848be4817a5cf9bd6c00a9f0ffc1ccc485d7 | Ruby | AlexanderOsborne/restarurant-2010 | /lib/restaurant.rb | UTF-8 | 605 | 3.484375 | 3 | [] | no_license | class Restaurant
attr_reader :name, :dishes, :opening, :closing
def initialize(opening, name, dishes = [])
@opening = opening
@name = name
@dishes = dishes
@closing = closing
end
def opening_time
@opening
end
def closing_time(hours)
@closing = @opening.to_f + hours.to_f
end
def... | true |
df1f760474f9294d7544e30556c5f4d7179e53a2 | Ruby | Saoma1/rails-movie-checker | /app/models/web_scrapper.rb | UTF-8 | 2,302 | 2.546875 | 3 | [] | no_license | require 'kimurai'
class WebScrapper < Kimurai::Base
@name = 'torrent_spider'
@engine = :selenium_firefox
@start_urls = ['https://1337x.to/cat/Movies/']
@config = {
user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36",
before_request: {... | true |
50eb3f5cddac5c0136c117d60c6ca3d8b5ccd723 | Ruby | sbrook13/ruby-enumerables-array-count-lab-den01-seng-ft-080320 | /lib/array_count.rb | UTF-8 | 153 | 3.359375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def count_strings(array)
array.count { |element| element.is_a?(String)}
end
def count_empty_strings(array)
array.count {|element| element == ""}
end | true |
ab42aacd0d7c2c0b2245bab267d3dcdbe86462d6 | Ruby | sivanpatel/bitmap_editor | /lib/commands/paint_vertical_line.rb | UTF-8 | 334 | 3.046875 | 3 | [] | no_license | module Commands
class PaintVerticalLine
def initialize(bitmap)
@bitmap = bitmap.bitmap_table
end
def run(args)
row = args[0].to_i - 1
@bitmap.each_with_index do |column, i|
column[row].change_colour(args[3]) if ((args[1].to_i - 1)..(args[2].to_i - 1)).include?(i)
end
... | true |
cf6df59ea97399b250d966f545af08f83c473ef1 | Ruby | mykola-kyryk/url_meta_data | /lib/url_meta_data/parser.rb | UTF-8 | 919 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
module UrlMetaData
class Parser
private_class_method :new
def self.parse(document)
new(document).send(:parse)
end
private
attr_reader :document
def initialize(document)
@document = Nokogiri::HTML.parse(document) do |config|
config.options = Nokogiri:... | true |
5e4ff6ec5812b310f269606e69a528c9c497e1c9 | Ruby | um-eng-web/grupo1 | /BetESS/Business/utilizador.rb | UTF-8 | 399 | 2.921875 | 3 | [] | no_license | class Utilizador
@@ADMIN = 1
@@APOSTADOR = 2
@@BOOKIE = 3
attr_accessor :nome
attr_accessor :email
attr_reader :password
def initialize (name = '', email = '', password = '')
@nome = name
@email = email.downcase
@password = password
end
def ==(o)
o.class == self.class && o.nome == s... | true |
c25af1db4cb9e7ee9a848ad0bf12588bdbb9c53b | Ruby | PascaleB1/lrthw | /ex5.rb | UTF-8 | 372 | 3.78125 | 4 | [] | no_license | puts "Let's talk about #{'Zed A. Shaw'}."
puts "He's #{74} inches tall."
puts "He's #{180} pounds heavy."
puts "Actually that's not too heavy."
puts "He's got #{'Blue'} eyes and #{'Brown'} hair."
puts "His teeth are usually #{'White'} depending on the coffee."
# this line is tricky, try to get it exactly right
puts "I... | true |
2f7e123f2dfaad631f6716a7c5dd1e71131c59df | Ruby | chesk98/BackEndHw | /hw1/homewrok1.rb | UTF-8 | 901 | 4.15625 | 4 | [] | no_license |
def full_name(first_name, last_name, title)
# Example comment line
name = nil
if title && first_name && last_name
name = title + " " + first_name + " " + last_name
elsif title && last_name
name = title + " " + last_name
elsif first_name && last_name
name = first_name + " " + last_name
elsif f... | true |
a1ed70290294f3e1dd66ac48bf10e3cb284bd486 | Ruby | jvoegele/externals | /lib/externals/scms/git_project.rb | UTF-8 | 3,912 | 2.671875 | 3 | [
"MIT"
] | permissive | require File.join(File.dirname(__FILE__), '..', 'project')
module Externals
class GitProject < Project
def default_branch
'master'
end
private
def co_or_up command
opts = resolve_opts(command)
puts "path is #{path} repository is #{repository}"
if path != '.'
(rmdirc... | true |
41333d6a9f724c5f74a9c7eb2a356acd591095eb | Ruby | edromero86/Ruby | /ex15.rb | UTF-8 | 590 | 3.765625 | 4 | [] | no_license | filename = ARGV.first
txt = open(filename)
puts "Here's your file #{filename}:"
puts txt.read
print "Type the filename again: "
file_again = $stdin.gets.chomp
txt_again = open(file_again)
puts txt_again.read
# open() method opens the file.
# read() method reads the contents of the file. You can assign the resul... | true |
778072f64bc2a0fbac72bab66574f3b2fe2da734 | Ruby | dalexj/food_train | /test/models/group_test.rb | UTF-8 | 754 | 2.625 | 3 | [] | no_license | require "test_helper"
class GroupTest < ActiveSupport::TestCase
def test_has_many_trains
group = create_group
trains = 5.times.map { create_train group: group }
assert_equal 5, group.trains.count
trains.each do |train|
assert_includes group.trains, train
end
end
def test_cant_make_ano... | true |
bf474e9041b64ded36335fe82e5b3ad57b38a426 | Ruby | fwg-dev/my-collect-onl01-seng-ft-061520 | /lib/my_collect.rb | UTF-8 | 176 | 2.9375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | list =["Tim Jones", "Tom Smith", "Jim Campagno"]
def my_collect(languages)
i = 0
lang_caps = []
while i < languages.length
lang_caps << yield(languages[i])
i += 1
end
lang_caps
end
| true |
33503fa2fa454cf6cdf2ab49581d990cf7e4a6e8 | Ruby | amnotme/42_Hack | /src/solutions/two_sum_solution.rb | UTF-8 | 197 | 3.59375 | 4 | [] | no_license |
class Array
def two_sum
pairs = []
(0...length).each do |i|
((i + 1)...length).each do |j|
pairs << [i, j] if self[i] + self[j] == 0
end
end
pairs
end
end
| true |
139b5674adf10ba0559e922d11cbd3fa0e7dccfd | Ruby | itggot-lukas-persson/standard-biblioteket | /lib/next_number.rb | UTF-8 | 134 | 2.765625 | 3 | [] | no_license | # Denna funktion tar ett heltal som input
# och returnerar nästa tal i talkedjan.
def next_number(num)
return num + 1
end
| true |
c9c1d0377150c51f4212adbc462aaf0d5e82c006 | Ruby | KotobaMedia/ecr-vacuum | /ecr-vacuum.rb | UTF-8 | 2,776 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative "./lib/setup"
DRY_RUN = !!ENV["DRY_RUN"]
KEEP_COUNT = 10
region = ENV["AWS_REGION"] || "us-east-1"
ecr = Aws::ECR::Client.new(region: region)
repositories = ecr.describe_repositories({max_results: 100})
puts "Starting at #{Time.now.to_s}"
if DRY_RUN
puts "[!!] Dry run mode en... | true |
b253e6b04bbee757284417e6166780dcd58ec598 | Ruby | strikeroff/helpful_utils | /lib/helpful_utils/core_ext/kernel.rb | UTF-8 | 1,258 | 2.953125 | 3 | [] | no_license | module Kernel # :nodoc:
# Переключение области видимости на объект.
# Использовать осторожно. Рекоммендуется применять, когда в коде идет несколько операций
# над одним объектом. Таким образом следующий код:
#
# Gionet.contexts.set_context(:region, :volga)
# Gionet.contexts.set_context(:site, "gionet... | true |
13b3b6adc417cd0c4007fdbc626c02e207e9b279 | Ruby | AlineFreitas/nsi_minicurso | /06/ContaCorrente.rb | UTF-8 | 608 | 3.59375 | 4 | [] | no_license | #coding:utf-8
#6) Crie uma classe que modele uma conta corrente e que permita definir e consultar o numero da conta e o nome correntista, consultar o saldo e fazer depósitos e saques.
class ContaCorrente
attr_accessor :saldo
attr_reader :nome_titular, :numero_conta
def initialize(nome_titular, numero_conta, saldo=... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.