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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
202a77a1e7bb92c576eb8bf3bcd730409486dc8f | Ruby | WarHatch/Mastermind-ruby | /lib/game.rb | UTF-8 | 4,086 | 3.5625 | 4 | [] | no_license | require_relative 'AI'
# Component for Board class
class BreakAttempt < MastermindObject
attr_accessor :break_attempt
attr_reader :feedback, :feedback_count
def initialize
@break_attempt = Array.new(PEG_SPACES)
@feedback = Array.new(PEG_SPACES)
@feedback_count = 0
end
def add_feedback_peg(feedba... | true |
01de4020241292e6af6a6d27b8944582eaf2b0b8 | Ruby | ysawa/sengine | /lib/sbot/board.rb | UTF-8 | 10,449 | 3.015625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
module SBot
class Board
SIZE = 111
# board sized with 111 pieces
attr_accessor :board
attr_accessor :number
# hands of sente and gote
attr_accessor :sente_hand
attr_accessor :gote_hand
# kikis of sente and gote
attr_accessor :sente_kikis
attr_accessor... | true |
643c0254bd0ad284fccbcd7f79a46871d7874c5b | Ruby | IlitaKu/ruby-intro-to-arrays-lab-london-web-082619 | /lib/intro_to_arrays.rb | UTF-8 | 373 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def instantiate_new_array
new = []
end
def array_with_two_elements
new = [1,2]
end
def first_element(new)
new.first
end
def third_element (new)
new[2]
end
def last_element(new)
new[-1]
end
def first_element_with_array_methods(new)
new.first
end
def last_element_with_array_methods(new)
new.l... | true |
90100d74ec329da0ab732df0728bbddc09b4e576 | Ruby | kevincai79/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 3,102 | 4.40625 | 4 | [] | no_license | # OUR ENCRYPT AND DECRYPT METHODS FOR SECRET AGENTS
# Input the text
# Split the text into single character,
# and replace it with a letter forward
# combine the new characters as a new string
def encrypt(text)
i = 0
new_text = "" # Declare an empty string to take the replace character
new_string = "" # Decl... | true |
ef1d5b662bfdba0838f983f364bf37a60e3becff | Ruby | katsuya245126/App-Academy-Projects | /Finished/previous_exercises/Tic-tac-toe/tic_tac_toe_v3/computer_player.rb | UTF-8 | 213 | 3.453125 | 3 | [] | no_license | class ComputerPlayer
def initialize(mark)
@mark = mark
end
def mark
@mark
end
def get_position(legal_positions)
pos = legal_positions.sample
puts "BOT chooses #{pos}!"
pos
end
end | true |
ebba586e84e5929874cc6483a892aefc98745d05 | Ruby | Holy87/rpgvxace | /universal_module.rb | UTF-8 | 44,702 | 2.890625 | 3 | [] | no_license | $imported = {} if $imported == nil
$imported["H87_UniversalModule"] = 1.6
=begin
==============================================================================
■ Holy87's Universal Module
version 1.6.2 - EN
User difficulty: ★★★
License: CC-BY. Everyone can distribute this script and use in their fr... | true |
10488c78e92d0f3cb223c08575ea073b47d417f7 | Ruby | QBFreak/NightMAREbot | /sbin/newsbot/plugins/show_news.rb | UTF-8 | 3,786 | 2.953125 | 3 | [] | no_license | =begin
Contains several methods to display posts in various ways.
=end
class NewsCommand < Command
def display_news news_array
news_array = get_news_from news_array if news_array.kind_of? Integer
return news_array.map{|n| n.short_display}.join("\n")
end
def get_news_from index=-1
p_arr = []
if index == -1... | true |
65b557ff508f5d091c91e0da5a4c145c1fec946e | Ruby | s-wigg/algorithms | /lib/selection_sort.rb | UTF-8 | 779 | 4.09375 | 4 | [] | no_license | # time complexity is O(n^2) or quadratic
def find_smallest(array)
smallest = array[0]
smallest_index = 0
array.drop(1).each_with_index do |value, index|
# print "value: #{value} "
# puts "Index: #{index}"
next unless value < smallest
smallest = value
# puts "smallest: #{smallest}"... | true |
f410a8ebb3f18fefe426da30449f33466709f087 | Ruby | codeship/bitbucket | /lib/bitbucket_rest_api/repos/commits.rb | UTF-8 | 1,766 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | # encoding: utf-8
module BitBucket
class Repos::Commits < API
VALID_KEY_PARAM_NAMES = %w(include exclude pagelen).freeze
# Gets the commit information associated with a repository. By default, this
# call returns all the commits across all branches, bookmarks, and tags. The
# newest commit is first... | true |
8612abe881173a21427907f97cac789e05b9cadf | Ruby | paradox460/subbot | /plugins/subreddit_management.rb | UTF-8 | 1,720 | 2.609375 | 3 | [
"MIT"
] | permissive | require './lib/common_functions'
require "active_support/core_ext/array/conversions"
class SubredditManagement
include Cinch::Plugin
include CommonFunctions
set :plugin_name, "Subreddit Management"
set :help, "Usage: #{CONFIG['prefix']}subreddit (add|del|list) <subreddit>"
match /subreddit add ([[:alnum:]]... | true |
9064ddd1f667e2b8ead587345bd17d11390b2f45 | Ruby | sunlightlabs/tcorps-earmarks | /vendor/gems/rscribd-1.0.1/lib/scribddoc.rb | UTF-8 | 11,486 | 3 | 3 | [
"MIT"
] | permissive | require 'uri'
module Scribd
# A document as shown on the Scribd website. API programs can upload documents
# from files or URL's, tag them, and change their settings. An API program can
# access any document, but it can only modify documents owned by the logged-in
# user.
#
# To upload a new document to... | true |
2a8aaf88b2ef5c11099544222d190a6233584396 | Ruby | nagano564/operationcode_backend | /app/lib/format_data.rb | UTF-8 | 372 | 3.40625 | 3 | [
"MIT",
"CC-BY-3.0"
] | permissive | class FormatData
# Converts a comma-separated string into an array of its contents.
#
# @param comma_separated_string [String] String of comma-separated values, i.e '80123, 80202'
# @return [Array] An array of strings, i.e. ['80123', '80202']
#
def self.csv_to_array(comma_separated_string)
comma_separa... | true |
e45701342ade8ad441af9488d961737d5e9283a5 | Ruby | codegorilla/lang | /builders/IntBuilder.rb | UTF-8 | 7,561 | 3.390625 | 3 | [
"MIT"
] | permissive | class IntBuilder
def initialize ()
@Int = TauObject.new($Class, "<class 'Int'>")
end
def makeRaw (value)
TauObject.new(@Int, value)
end
def make (params)
makeRaw(params[0].value)
end
def bor (params)
x = params[0]
y = params[1]
result =
case y.type
when @Int then Ta... | true |
d4166c1cc7e2a36f9d74daa9bfecdf83685a0e54 | Ruby | SamiZhang/Phase-0 | /week-5/gps2_2.rb | UTF-8 | 3,925 | 4.5625 | 5 | [
"MIT"
] | permissive | # Method to create a list
# input: string of items separated by spaces (example: "carrots apples cereal pizza")
# steps:
# Create a method named create_list and it will accept a string as input
# Create hash for method create_list with default value for each key equal to 1
# Split string into individual items an... | true |
bb5a53ee30ed9eb09081309e03ae725d83f1dad1 | Ruby | peppetrombetta/webgl | /lib/web_gl/world.rb | UTF-8 | 1,634 | 2.75 | 3 | [] | no_license | class WebGL::World
class Camera
attr_accessor :right, :up, :view, :position, :look_at
def changed?
orientation_changed? || position || look_at
end
def orientation_changed?
right || up || view
end
def js_lookat(name)
result = ""
result.concat "#{name}.setP... | true |
8bcee7742351f2dd12d38eb1cffc083b6efad925 | Ruby | adamamo17/nfl_app | /spec/models/coach_spec.rb | UTF-8 | 3,094 | 2.765625 | 3 | [] | no_license | # == Schema Information
#
# Table name: coaches
#
# id :integer not null, primary key
# name :string(255)
# team :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# password_digest :string(255)
#
require 'spec_helper... | true |
909d27dff750bc9bdd869cf5b95c6a9759f65c47 | Ruby | J-Michael-Brown/Anagrams-and-Antigrams | /lib/seporite_methods.rb | UTF-8 | 1,256 | 3.515625 | 4 | [
"MIT"
] | permissive | require('Grammable')
def for_each_grammable(input_word, *statements)
# found 'reject(&:empty?)' logic on stack overflow by Matt Greer @https://stackoverflow.com/questions/5878697/how-do-i-remove-blank-elements-from-an-array
for_word = input_word.split(/\W/).reject(&:empty?).join
check_words = []
statements.eac... | true |
48df426cc6d46279c70289e7981f3dcfa00f9d9e | Ruby | eli-zbth/DL_Fundamentos_Ruby | /02_Ciclos_y_metodos/01_desafios/solo_pares2.rb | UTF-8 | 158 | 2.875 | 3 | [] | no_license | tope = ARGV[0].to_i
i =1
mostrados=0
res=""
while (mostrados<tope)
if i%2 ==0
res=res+ " #{i}"
mostrados +=1
end
i+=1
end
res[0]=""
print res+"\n"
| true |
5228e137d3ae41be21ce0bb6c58291277ad63731 | Ruby | aman29april/Hatchways-Blog | /app/services/post_sort_transformer.rb | UTF-8 | 365 | 2.984375 | 3 | [] | no_license | class PostSortTransformer
def initialize(sort_by:, direction:)
# default sort by 'id' and direction is asc
@sort_by = sort_by || 'id'
@is_desc = direction == 'desc'
end
def transform(data)
sort(data)
end
private
def sort(data)
response = data.sort_by { |post| post[@sort_by] }
@is_... | true |
d9333baa800d66518afc2ed5c03c2a84ce41c3ec | Ruby | zitom4/prct08 | /spec/matrices_spec.rb | UTF-8 | 1,918 | 3.140625 | 3 | [] | no_license | require './lib/matrices.rb'
require '/home/alu4101/datos/homes.rala/LPP/prct07/lib/fraccion.rb'
describe Matriz do
before :each do
@M1 = Matriz.new(2,2)
@M1[0] = [1,1]
@M1[1] = [2,2]
@M2 = Matriz.new(2,2)
@M2[0] = [1,1]
@M2[1] = [2,2]
#### PRACTICA ####
@F1=Fraccion.... | true |
c8e6801601bc3d7cb32c8bcae5fd1b854a4a9b7f | Ruby | usman-tahir/rubyeuler | /neweuler10.rb | UTF-8 | 254 | 3.71875 | 4 | [] | no_license | # http://projecteuler.net/problem=10
require 'prime'
def sum_of_primes_below(number)
accumulator_array =[]
Prime.each(number) do |prime|
accumulator_array << prime
end
accumulator_array.inject(:+)
end
puts sum_of_primes_below(2_000_000) | true |
c2591fd048b47ac0f351f8ba5aebafa1e7b3c1c1 | Ruby | mikey-roberts/bowling-challenge-ruby | /lib/rules.rb | UTF-8 | 643 | 3.046875 | 3 | [] | no_license | module Rules
MAXIMUM_FRAMES = 10
MAXIMUM_PINS = 10
MAXIMUM_THROW = 10
# Throw Validation
def strike?
first_throw == MAXIMUM_PINS
end
def spare?
first_throw + second_throw = MAXIMUM_PINS
end
def pins_hit?
both_throws != 0
end
def gutter?
both_throws == 0
end
def... | true |
c86955eecdce5661cafd3d4786a565b174b1c9a1 | Ruby | stupendousC/dijkstra | /lib/dijkstra.rb | UTF-8 | 3,247 | 3.484375 | 3 | [] | no_license | ##### I'M LEAVING IN MY PRINT STATEMENTS BC IT HELPS ME REMEMBER WHY I DID WHAT I DID...
def dijkstra(adjacency_matrix, start_node)
puts "==============\nADJACENCY MATRIX"
adjacency_matrix.each do |r|
p r
end
puts "==============\n\n"
#int nVertices = adjacencyMatrix[0].length;
num_nodes = a... | true |
6998e2f607c5d9d518f4cc8517c3777c329aeaca | Ruby | sebaureta/E6CP2A1 | /3 strings/ejercicio2.rb | UTF-8 | 458 | 4.125 | 4 | [] | no_license | # Construir un arreglo de los nombres de todos sus compañeros y en base a él:
# 1. Imprimir todos los elementos que excedan más de 5 caracteres.
# 2. Crear un arreglo nuevo con todos los elementos en minúscula.
# 3. Crear un método que devuelva un arreglo con la cantidad de caracteres que tiene cada nombre.
mates = %w... | true |
52d771f5c6f524619cb7805040da319c1ebfba80 | Ruby | Napwob/Ruby-Temperature-Converter | /spec/states/second_scale_spec.rb | UTF-8 | 2,005 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
require_relative './../../src/states/read_second_scale'
require_relative './../../src/states/read_value'
require_relative './../../src/io_adapter'
describe States::ReadSecondScale do
let(:adapter) { double 'IO_Adapter' }
before do
allow(IO_Adapter).to receive(:instance).and_retu... | true |
3280c32454c63d9f7ffd47da983b34404ad8848a | Ruby | AlejandroDeheza/TADP-TP | /ruby/lib/prueba.rb | UTF-8 | 5,759 | 2.71875 | 3 | [] | no_license | class Prueba
def materia
:tadp
end
end
#estaba en "ObjetoPersistible"
=begin
# define metodos y accesors para las clases persistibles
def self.included(clase)
clase.singleton_class.send(:attr_reader, :atributos_persistibles)
clase.singleton_class.send(:attr_accessor, :tabla)
end
=end
# estaba e... | true |
a646b924b31ee8f793997a337d5f461870dd7924 | Ruby | Andriamanitra/adventofcode2020 | /day02/fun.rb | UTF-8 | 1,105 | 3.28125 | 3 | [] | no_license | # Let's try to solve it with ONLY regex!
# I'm not happy with using MatchData#captures -method
# because it returns an ARRAY(!) which is CLEARLY
# NOT REGEX. But this is the best I have come up
# with so far...
input = ARGF.read
def puts(x)
STDOUT.puts Time.now.strftime("[%a %H:%M:%S.%L] #{x}")
end
line = /(\d... | true |
a3c63795d9d49bde6785ab1d441569866014f8de | Ruby | thestoneage/isaak | /lib/universe.rb | UTF-8 | 1,112 | 3.15625 | 3 | [] | no_license | class Universe
attr_reader :width, :height, :things
def initialize(width, height, gravity)
@things = []
@width = width
@height = height
@border = true
@gravity = gravity
end
def update
@things.each do |thing|
if @border
bounce(thing)
end
mutual_gravity(thing)... | true |
56b0d246991725d5800fe534ba9d1ca56a8ac862 | Ruby | brady-robinson/ls-rb101 | /small_problems/medium2-10.rb | UTF-8 | 1,149 | 4.4375 | 4 | [] | no_license | # problem: write a method that employs bubble sort algorithm
# data: array
# input: array
# output: sorted array!
# alg:
# - this is going to need a nested loop
# - initialize a variable that will change when any two integers are swapped
# - initialize a count variable
# - start a loop
# - in the outer loop, befo... | true |
17b1b0216065d26d7470d570b2da9ec32e95c3d0 | Ruby | sergii/daily-ruby-tips | /114/struct_block.rb | UTF-8 | 1,224 | 4.75 | 5 | [] | no_license | # Ruby inheritance is pretty cool, and today's we look at how sub classing a Struct object
# and using the Struct block can return the same result.
# A normal struct object doesnt have a very pretty output
Park = Struct.new(:location, :capacity)
cp = Park.new("Central Park", "1,200,000")
puts cp
#=> #<struct Park loca... | true |
db6495da7f4e6ea2c9a79f6d7f12653a7a21237e | Ruby | aellonk/ttt-3-display_board-example-v-000 | /lib/display_board.rb | UTF-8 | 299 | 3.265625 | 3 | [] | no_license | # Define a method display_board that prints a 3x3 Tic Tac Toe Board
def display_board
cell = " "
cell_divider = "|"
row = cell + cell_divider + cell + cell_divider + cell
row_divider = "-----------"
puts row
puts row_divider
puts row
puts row_divider
puts row
end
display_board
| true |
a9e0a37f217c0f281965516b6a2c18301f0f0f3a | Ruby | bentrevor/game-of-life | /run.rb | UTF-8 | 488 | 3.140625 | 3 | [] | no_license | require './lib/cells'
require './lib/game'
n = 120**2
random_grid = Array.new n
n.times do |i|
random_grid[i] = [0,1].sample
end
game = Game.new random_grid
def show(game)
grid = game.cells.grid
grid.each_with_index do |cell, index|
char = if cell == 0
' '
else
'@'
... | true |
9ab6924cdf6ad6b9c30a82993d03ff75859e1bac | Ruby | rajat-11223/aprroveforme | /spec/support/stripe_helpers.rb | UTF-8 | 468 | 2.5625 | 3 | [] | no_license | module StripeHelpers
def fill_stripe_element(card, exp, cvc, postal='')
card_iframe = all('iframe')[0]
within_frame card_iframe do
fill_by_char card, find_field('cardnumber')
fill_by_char exp, find_field('exp-date')
fill_by_char cvc, find_field('cvc')
fill_by_char postal, find_fiel... | true |
03218a1ef18dbc79b61b9df8593c9196c7758d2a | Ruby | kbutkus/fibanocci | /Fibonacci.rb | UTF-8 | 598 | 3.90625 | 4 | [] | no_license | def iterative_fib(number)
array = []
counter = number
a = 0
b = 1
c = 0
print "#{a}, "
until counter == 0
c = a + b
a = b
b = c
print "#{c}, "
counter = counter - 1
end
puts
end
@array = [0,1]
def recursive_fib(number)
return number if number < 2
@array[number] = recursive_fib(number - 1)... | true |
442c918a15ae20a506c971e673ee089cd5081a00 | Ruby | kcin46/CMSC498JPageRank | /SubredditInfo.rb | UTF-8 | 206 | 2.890625 | 3 | [] | no_license | class SubredditInfo
attr_accessor "name" , "posts", "posts_map"
def initialize(name, posts)
@name = name
@posts = posts
@posts_map = Hash.new ()
end
def add_post(link)
@posts << link
end
end | true |
9b64eaefe3c2f63bd38adee57660c2925972a9ff | Ruby | jihao/ruby_scripts_for_fun | /meta_programming/meta/meta_test.rb | UTF-8 | 1,436 | 3.046875 | 3 | [] | no_license | #!/usr/bin/env ruby -wKU
require 'test/unit'
class C
def self.metaclass # C.singleton_class
class << self;self;end
end
def self.class_method
puts "class_method defined in C.metaclass = #{self.metaclass}"
end
def metaclass # C.new.singleton_class
class << self;self;end
end
end
class MetaT... | true |
027397c8501a31d17fe45cfdbbc0c68bb3693f76 | Ruby | Banzar/rubycode | /rand.rb | UTF-8 | 106 | 3.59375 | 4 | [] | no_license | # rand.rb
# Randoms in ruby
elg = rand(100)
puts "I have " + elg.to_s() + " apples in my apple tree!"
| true |
a4de2fd329e2ecbbaba9217e48d3f70a61bd8805 | Ruby | h-shima/rbs | /lib/rbs/json_schema/generator.rb | UTF-8 | 13,074 | 2.71875 | 3 | [
"BSD-2-Clause",
"Ruby"
] | permissive | require "json"
require "uri"
require "rbs/json_schema/validation_error"
module RBS
module JSONSchema
class Generator
attr_reader :stringify_keys
attr_reader :output
attr_reader :stdout
attr_reader :stderr
attr_reader :path_decls
attr_reader :generated_schemas
# Alias de... | true |
4ed495fb151bafc093987e4e9d8093de5b963680 | Ruby | johnvm914/object_oriented_ruby | /inheritance_example.rb | UTF-8 | 660 | 3.640625 | 4 | [] | no_license | class Vehicle
def initialize
@speed = 0
@direction = 'north'
end
def brake
@speed = 0
end
def accelerate
@speed += 10
end
def turn(new_direction)
@direction = new_direction
end
end
class Car < Vehicle
def initialize
super
@fuel = "regular"
@make = "Fiat"
@model ... | true |
9ed4280878a9c75450ad01be61088bfa98a85464 | Ruby | henteko/review-and-css-typesetting | /articles/review-ext.rb | UTF-8 | 2,276 | 2.578125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
ReVIEW::Compiler.defblock :imagetalkl, 1..2
ReVIEW::Compiler.defblock :imagetalkr, 1..2
ReVIEW::Compiler.defsingle :mycolumnbegin, 0
ReVIEW::Compiler.defsingle :mycolumnend, 0
ReVIEW::Compiler.defsingle :questionbegin, 0
ReVIEW::Compiler.defsingle :questionend, 0
ReVIEW::Compiler.defsingle :answerbegi... | true |
144bfa88c47d53d08dae278b85e3f6f5f64177c6 | Ruby | jmclean-coder/sample_code | /13-apis/db/seeds.rb | UTF-8 | 783 | 2.953125 | 3 | [] | no_license | url = "https://pokemon-go1.p.rapidapi.com/pokemon_stats.json"
#sent hte request and got the data
pokemon_stats = RestClient::Request.execute(method: :get,
url: "https://pokemon-go1.p.rapidapi.com/pokemon_stats.json",
headers:{
"X-RapidAPI-Host" => "pokemon-go1.p.rapidapi.com",
"X-RapidAPI-Key" => ENV... | true |
6c9b21981e486899b3bfe7e482adaa49fb986dae | Ruby | andresporras3423/bowling_game | /lib/game.rb | UTF-8 | 3,453 | 3.1875 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'player'
require_relative 'valid_score'
class Game
include ValidScore
attr_reader :players
def initialize(relative_path, request_output)
@players = {}
error_message = read_file_content(relative_path)
if error_message != ''
puts error_message
... | true |
399379e5f096f03867e3e22786b8945d38292ad8 | Ruby | LeahB8/badges-and-schedules-london-web-career-040119 | /conference_badges.rb | UTF-8 | 636 | 3.890625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
speakers = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(speakers)
speakers.map do |speaker|
badge_maker(speaker)
end
end
def assign_rooms(speakers)
attendee_array = []
speake... | true |
abe69d961c9cdab6b265670594b832e6f76cce4e | Ruby | magic8baller/web-071717 | /04-oo-review/lib/zoo.rb | UTF-8 | 2,970 | 4.21875 | 4 | [] | no_license | class Animal
# An animal belongs to a location
attr_accessor :species, :location # Remember that the attr_accessors correspond to a name of a column on our table.
@@all = []
def self.all
@@all
end
def initialize(species)
@species = species
self.class.all << self # this line is the same as say... | true |
680c3185244ed89e9d256f21d7b6b99383b6dec2 | Ruby | burakkocak884/reverse-each-word-ruby-cartoon-collections-000 | /reverse_each_word.rb | UTF-8 | 355 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def reverse_each_word(array)
new_array = array.split(" ")
reversed_array = new_array.each do |word|
word.reverse!
end
reverse_each_word = reversed_array.join(" ")
end
def reverse_each_word(array)
array1 = array.split(" ")
reversed_array1 = array1.collect do |word|
word.reverse!
end
reverse_each_wor... | true |
449259fcf79b06cb27488795cd6535c1c09af6ca | Ruby | stan761/kanzapanoid | /lib/fader.rb | UTF-8 | 361 | 3.46875 | 3 | [] | no_license | class Fader
attr_accessor :value, :target, :time, :elapsed
def initialize(value=0.0)
@value = value
@target = @value
@time = 0.0
@elapsed = 0.0
end
def to(target, time)
@target = target
@time = time
@elapsed = 0.0
end
def update
if @target != @value
@value -= (@value - @target) / (@time - @e... | true |
b7179f7f03b78d40e2d58ff82b538cf6a538332f | Ruby | jackzones/client_server_application | /server_application/lib/server/tcp_logger_server.rb | UTF-8 | 1,498 | 3.015625 | 3 | [] | no_license | class TCPLoggerServer
def initialize(hostname=nil, port=nil, log_file_name=nil)
@host = hostname || 'localhost'
@port = port || 20000
file_name = log_file_name || 'server.log'
@log_file_path = File.join('server_log', file_name)
Thread.abort_on_exception = true
end
# Create TCPServer and acc... | true |
af9538213aba84cc35a5369039cd45fcc9f49d23 | Ruby | lamagnotti/codewars | /high_and_low.rb | UTF-8 | 468 | 4.34375 | 4 | [] | no_license | # In this little assignment you are given a string of space separated numbers,
# and have to return the highest and lowest number.
def high_and_low(numbers)
new_array = []
new_string = numbers.split
new_string.each do |n|
new_array << n.to_i
end
max_string = new_array.max
min_string = new_array.min
"... | true |
f5dd0b6ab5a268522255d94974d05aae5fad1c34 | Ruby | murraymel/air | /rspec_test/dog_spec.rb | UTF-8 | 115 | 2.59375 | 3 | [] | no_license | describe 'A Dog' do
it 'wags tail when you petted' do
d = Dog.new
d.pet.should eq('wags tail')
end
end
| true |
f565d086cf463d429c46fb895a8f368758eb0a40 | Ruby | tcd/coolkit | /lib/coolkit/wip/core_ext/titleize.rb | UTF-8 | 545 | 3.625 | 4 | [
"MIT"
] | permissive | module Coolkit
# Returns a copy of a string with the first letter of each word capitalized.
# @return [String]
def titleize()
return self.split(" ")
.map(&:capitalize!)
.join(" ")
end
# @return [String]
def titleize2(string)
words = self.split(" ")
skips = ["and",... | true |
55387b9ffde9fad03f1383bf780da063a518c068 | Ruby | Themitchell/follower-maze | /lib/follower_maze/user_store.rb | UTF-8 | 1,478 | 2.90625 | 3 | [] | no_license | require 'singleton'
module FollowerMaze
class UserStore
@store = {}
class NotFoundError < StandardError; end
class << self
def add user
@store[user.id] = user
Logger.debug "UserStore: Created user with id: #{user.id}" if user
user
end
def create_or_update id,... | true |
89f32dc44c403bfe294702df14a1fe55cd9c3ec1 | Ruby | SebastianWikander/Korean-Manual | /spec/verb_spec.rb | UTF-8 | 2,786 | 2.90625 | 3 | [] | no_license | #!/bin/env ruby
# encoding: utf-8
require 'verb'
describe Verb do
it "should conjugate the verb 가다" do
verb = Verb.new("가다")
verb.present.stem.should eq("가")
verb.present.plain.should eq("간다")
verb.present.informal.should eq("가")
verb.present.polite.should eq("가요")
verb.present.formal.should... | true |
ecd21e6a30a8cceb74aba45e5426308cb7033a9a | Ruby | dhopz/oystercard | /spec/oystercard_spec.rb | UTF-8 | 2,337 | 3.078125 | 3 | [] | no_license | require 'oystercard'
describe OysterCard do
let(:oystercard) { OysterCard.new }
let(:station) { double :station }
it 'get my balance' do
expect(subject.balance).to eq 0
end
it 'adds money to my balance' do
subject.add_funds(10)
expect(subject.balance).to... | true |
6a96fff2d747c31cf439bf913252592703aa25a7 | Ruby | suncoast-devs/cohort-xii | /week-08/day-01-intro-to-ruby/helloworld.rb | UTF-8 | 3,214 | 4.625 | 5 | [] | no_license | # let name = 'Gavin'
name = "Gavin"
# console.log(name)
puts(name)
score = 42
puts(score)
# message = `${name}, your score is ${score}`
message = "#{name}, your score is #{score}"
puts(message)
# Array literals, just like in JavaScript
# scores = [100, 42, 60, 12, 0, 99 ]
scores = [100, 42, 60, 12, 0, 99]
#... | true |
53912853706f2be40428735c002d28d734b7b60d | Ruby | nyc-sea-lions-2015/Jester | /db/seeds.rb | UTF-8 | 3,312 | 2.671875 | 3 | [] | no_license | ["bcheng90", "danasselin", "ebutler90", "gellieb", "hoathenguyen85", "kevalwell", "laurennicoleroth", "maxrater", "mbouzi", "notika314", "notryanb", "phanendar", "rimmesbe", "sabron13", "samguergen", "steppinlo", "suprfrye", "tracyteague", "queerviolet", "linkblaine"].each do |user|
User.create(name: user, password: ... | true |
ca9b9383e2fe10d7fc891059301a39e6548dac82 | Ruby | gniquil/sudoku_validator | /spec/lib/sudoku_validator_spec.rb | UTF-8 | 6,119 | 3.078125 | 3 | [] | no_license | require 'spec_helper'
require 'yaml'
describe SudokuValidator do
def create_validator(file_path=fixture_path('valid_complete.sudoku'))
SudokuValidator.new(file_path)
end
describe '#valid_array?' do
it 'returns false if there are repeats excluding "."' do
validator = create_validator
expect(... | true |
95933282eaee278b3b5efc1b7751782f992a509c | Ruby | eliav-lavi/specs-workshop | /lib/first/person.rb | UTF-8 | 342 | 3.59375 | 4 | [] | no_license | class Person
attr_reader :first_name, :last_name, :education_level
def initialize(first_name, last_name, education_level = 0)
@first_name = first_name
@last_name = last_name
@education_level = education_level
end
def full_name
"#{@first_name} #{@last_name}"
end
def educate!
@education... | true |
7622f2cf30dda853946595376ddad05da0e50b36 | Ruby | marshall405/sinatra-mvc-lab-atx01-seng-ft-042020 | /models/piglatinizer.rb | UTF-8 | 888 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
def piglatinize(words)
words_arr = words.split(" ")
latin_text = words_arr.map do |word|
latinize_word(word)
end
latin_text.join(" ")
end
def latinize_word(word)
if !word[0].downcase.scan(/[aeoui]/).empty?
return word... | true |
bac70b0e23a60d95f787c66530b2f008e8c7f4d9 | Ruby | GetTheFlightOut/Weather-API | /app/services/weather_service.rb | UTF-8 | 467 | 2.734375 | 3 | [] | no_license | class WeatherService
def self.conn
Faraday.new(url: 'http://api.openweathermap.org') do |req|
req.params['appid'] = ENV['WEATHER_API_KEY']
end
end
def self.weather_search(params)
response = conn.get('/data/2.5/onecall') do |req|
req.params['lat'] = params[:lat]
req.params['lon'] = p... | true |
f5424847481d4037a76842b441828bd2c7c5a10c | Ruby | ttillotson/TipTopTomes | /app/models/user.rb | UTF-8 | 2,693 | 2.578125 | 3 | [] | no_license | # == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# username :string not null
# email :string not null
# password_digest :string not null
# session_token :string not null
# created_at :datetime ... | true |
47cfbc45182394bfb7e0c443ab10fbfe1d0c7d87 | Ruby | benlavon/twgr | /chapter7/to_a.rb | UTF-8 | 350 | 3.796875 | 4 | [] | no_license | # Nice way of making an array
(1..5).to_a
Computer = Struct.new(:os, :manufacturer)
laptop1 = Computer.new("linux", "Lenovo")
laptop2 = Computer.new("os x", "Apple")
puts [laptop1, laptop2].map { |laptop| laptop.to_a }
def combine_names(first_name, last_name)
first_name + " " + last_name
end
names = ["David", "Blac... | true |
82590fe8a45683677825cdb6f17bbc8fc6ed53e6 | Ruby | Vratislav/saltpack-ruby | /lib/saltpack/armor.rb | UTF-8 | 10,397 | 3.265625 | 3 | [
"MIT"
] | permissive | module Saltpack
class << self
B64_ALPHAPBET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
B62_ALPHAPBET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
B85_ALPHAPBET = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu'
... | true |
2e7922fdba749a9239c6abe6a82e751c7c779d4e | Ruby | alu0100603453/prct07 | /spec/racional_spec.rb | UTF-8 | 3,207 | 2.96875 | 3 | [] | no_license | require "racional.rb"
describe Fraccion do
before :each do
@f1 = Fraccion.new(1,2)
#<<<<<<< HEAD
@f22 = Fraccion.new(2,3)
@f2 = Fraccion.new(25,5)
@f3 = Fraccion.new(5,15)
@f4 = Fraccion.new(5,15)
@f5 = Fraccion.new(1,3)
@f6 = Fraccion.new(7,5)
@f7 = Fraccion.new(-1,2)
end
describe "# Almacenamie... | true |
9756e8dbe51daa2aebe2c90844b15de556898c9a | Ruby | BlookHo/TreeFams | /app/models/concerns/similars_exclusions.rb | UTF-8 | 4,999 | 2.53125 | 3 | [] | no_license | module SimilarsExclusions
extend ActiveSupport::Concern
# in User model
module ClassMethods
######################################################################
# МЕТОДЫ ПРОВЕРКИ УСЛОВИЯ ИСКЛЮЧЕНИЯ ПОХОЖЕСТИ
######################################################################
# Метод определе... | true |
a889078addee630c1b8578f515548bf0a358a5c4 | Ruby | mayankagnihotri7/movie_listing_ruby | /spec/flicks/playlist_spec.rb | UTF-8 | 882 | 2.734375 | 3 | [] | no_license | require "flicks/playlist"
require "flicks/playlist_module"
module Flicks
describe PlayList do
before do
@playlist = PlayList.new("Max")
end
context "change the rank based on the number dice rolls" do
before do
@inital_rank = 10
@movie = Movie.new("goonies", @inital_rank)
... | true |
f0abc283fcb46514783002584572b2a3d8784b02 | Ruby | metricfu/metric_fu | /lib/metric_fu/data_structures/location.rb | UTF-8 | 3,535 | 2.921875 | 3 | [
"MIT"
] | permissive | module MetricFu
class Location
include Comparable
attr_accessor :file_path, :file_name, :line_number,
:class_name, :method_name, :simple_method_name, :hash, :hash_key
def self.get(file_path, class_name, method_name)
location = new(file_path, class_name, method_name)
@@locat... | true |
37cacf803f118b71f064bdd1587f8f0c4e632627 | Ruby | ahwkim/bewd_homework | /class_3_4_homework/99_bottles.rb | UTF-8 | 533 | 4 | 4 | [] | no_license | puts "Welcome to 99 Bottles of Beer on the Wall"
number = 99
while number >= 2
puts "#{number} bottles of beer on the wall, #{number} bottles of beer. Take one down and pass it around, #{number - 1} bottles of beer on the wall."
number = number - 1
end
puts "1 bottle of beer on the wall, 1 bott... | true |
30ac20569dc75ca6a171dab4b379283574af54b9 | Ruby | madx/termki | /spec/page_spec.rb | UTF-8 | 3,283 | 2.734375 | 3 | [] | no_license | describe TermKi::Page do
MockRevision = Struct.new(:checksum, :contents, :timestamp)
class MockRevision; def bind(page) end end
describe 'initialization' do
it 'initializes with a name' do
page = TermKi::Page.new('page')
page.name.should == 'page'
page.history.should.be.kind_of Array
... | true |
1323cbdd6ef6a7647cf0d28b224681f24f6bbc97 | Ruby | Alexander-Andrade/weblog_stat | /src/validators/file_missing_validator.rb | UTF-8 | 337 | 2.609375 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../models/result'
class FileMissingValidator
def initialize(filename)
@filename = filename
end
def validate
return Result.success if filename && File.exist?(filename)
Result.failure(filename, 'file parameter is missing')
end
private
attr_read... | true |
c445a148052c2de607b5a6f9a853088ee36880ed | Ruby | sebatapiaoviedo/desafio_arreglos | /promedio2.rb | UTF-8 | 261 | 3.3125 | 3 | [] | no_license | def promedio (grades, grades1)
sum_array = grades + grades1
ratings = 0
all_grades = sum_array.count
sum_array.each do |grades|
ratings += (grades/all_grades.to_f)
end
ratings
end
print promedio([1000, 800, 250], [300, 500,2500]) | true |
cb98fdfc2546a7b9410a1a1a0f24a75c6644ad7e | Ruby | bahelms/time_tracker | /spec/support/mocks/tasks_decorator_mock.rb | UTF-8 | 368 | 2.734375 | 3 | [] | no_license | class TasksDecoratorMock
attr_reader :user
def initialize(user)
@user = user
end
def tasks
tasks = []
5.times { tasks << Task.new(task_params(Time.current)) }
2.times { tasks << Task.new(task_params(2.weeks.ago)) }
tasks
end
private
def task_params(time)
{ user_id: user.id, ... | true |
77d05e494b139aa2697ab7d997de7036bf615d61 | Ruby | lukei8ii/mtg_online | /app/models/game.rb | UTF-8 | 1,357 | 2.921875 | 3 | [] | no_license | class Game
include Wisper::Publisher
attr_accessor :players
attr_accessor :stack
attr_accessor :turns
def initialize(players)
throw "A game needs at least 2 players" unless players.count > 1
@players = players
@stack = []
@turns = []
@players.each do |player|
player.get_ready sel... | true |
784193e915f61af04024d8e98741c1bbf36dd033 | Ruby | tfielder/RPN-Calculator | /RPN_test.rb | UTF-8 | 4,985 | 3.03125 | 3 | [] | no_license | gem 'minitest', '~> 5.2'
require 'minitest/autorun'
require 'minitest/pride'
require_relative 'RPN_class'
class RPNTest < Minitest::Test
def setup
@rpn = RPN.new
end
def test_creates_new_class
assert @rpn
end
def test_it_has_empty_stack
assert_equal [], @rpn.stack
end
def test_it_validates... | true |
94f73b2e81752e66b79be206397672704c6f5ebd | Ruby | mkrahu/launchschool-courses | /101_programming_foundations/02_small_programs/finding_greatest.rb | UTF-8 | 398 | 3.765625 | 4 | [] | no_license | def finding_greatest(numbers)
max_number = nil
return nil if !numbers.is_a? Array || numbers.empty?
numbers.each do |num|
next unless num.is_a? Integer
max_number ||= num
max_number = num if num > max_number
end
max_number
end
puts finding_greatest([1, 10, 25, 4, 12, -3])
puts finding_greatest... | true |
3afd9d209bfac22f96a623ee2caaf0b2433f3125 | Ruby | petertseng/adventofcode-rb-2016 | /08_2fa.rb | UTF-8 | 878 | 2.96875 | 3 | [
"Apache-2.0"
] | permissive | WIDTH = begin
arg = ARGV.find { |x| x.start_with?('-w') }
arg ? Integer(ARGV.delete(arg)[2..-1]) : 50
end
HEIGHT = 6
screen = Array.new(HEIGHT) { Array.new(WIDTH, false) }
ARGF.each_line { |l|
words = l.split
case words[0]
when 'rect'
cols, rows = words[1].split(?x).map(&method(:Integer))
rows.times... | true |
73fc4734c475e78e2e1e856a125f3af52bdc87ca | Ruby | lonelyelk/advent-of-code | /2019/21/lib.rb | UTF-8 | 2,942 | 3.203125 | 3 | [] | no_license | class Intcode
attr_reader :prg, :index
def initialize(prog: , input: [])
@input = input
@prg = prog.dup
@index = 0
@halt = false
@output = []
@relative_base = 0
end
def halt?
@halt
end
def input(data)
@input.push(data)
end
def bulk_input(arr)
@input += arr
end
... | true |
a236cb24b3e9579d9168d021d118f76038c57ee2 | Ruby | tom025/factory-toys | /spec/factory_toys/parser_spec.rb | UTF-8 | 3,959 | 3.15625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'spec_helper'
#implemented here to get tests to pass as in Rails Environment and not ruby core??
class String
def blank?
self.nil? or self == ''
end
end
describe FactoryToys::Parser do
context 'on initialization' do
it 'returns straight text in the under :base' do
parser = FactoryToys::Par... | true |
cbd729f2eb6963d7847cd1862bf51bc016bbcddb | Ruby | alu0100454741/Equipo-DJ-prct08 | /spec/matrix_spec.rb | UTF-8 | 528 | 3.0625 | 3 | [] | no_license | require 'matrix_main.rb'
require 'rspec'
describe "Conjunto de expectativas" do
before :each do
@matrix1 = Matrix.new("9 3 2\n4 6 7")
@matrix2 = Matrix.new("3 5 7\n8 9 3")
end
it "La matriz se muestra correctamente" do
@matrix1.show.should eq("[[9, 3, 2], [4, 6, 7]]")
end
it "Comprobando el ac... | true |
4dc9c2da5b115071cb941110e915020d84b23f4a | Ruby | enspiral/playhouse | /lib/playhouse/context.rb | UTF-8 | 2,575 | 2.875 | 3 | [
"MIT"
] | permissive | require 'active_support/core_ext/string/inflections'
require 'playhouse/part'
require 'playhouse/validation/actors_validator'
module Playhouse
class Context
class << self
def parts
@actor_definitions ||= []
end
def actor(name, options = {})
raise InvalidActorKeyError.new(self.... | true |
e9cba3d168e80f2de9b6adbfe016d51608564b52 | Ruby | a-woodworth/ls_projects | /lesson_5_advanced_collections/exercise_10.rb | UTF-8 | 602 | 4.25 | 4 | [] | no_license | # Given the following data structure and without modifying the original array, use the map method
# to return a new array identical in structure to the original but where the value of each integer
# is incremented by 1.
# [{a: 1}, {b: 2, c: 3}, {d: 4, e: 5, f: 6}]
original = [{a: 1}, {b: 2, c: 3}, {d: 4, e: 5, f: 6}]... | true |
8051289bc07831a9f1d7b572eb5ff6b1ed3c6f51 | Ruby | ethanrowe/rivet | /lib/rivet/utils.rb | UTF-8 | 1,883 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | module Rivet
module Utils
AUTOSCALE_DIR = "autoscale"
def self.die(level = 'fatal',message)
Rivet::Log.write(level,message)
exit
end
def self.ensure_minimum_setup
if Dir.exists?(AUTOSCALE_DIR)
true
else
Rivet::Log.info("Creating #{AUTOSCALE_DIR}")
Dir.... | true |
20bb2bceb67014247d68e6552b62bd41ad22ecf3 | Ruby | Robertfarb/W1D5 | /skeleton/lib/knight_path.rb | UTF-8 | 510 | 2.96875 | 3 | [] | no_license | require_relative '00_tree_node.rb'
class KnightsPathFinder
POSSIBLE_MOVES = [[-2, 1], [-2, -1], [2, -1], [2, 1], [1, 2], [1, -2], [-1, 2], [-1, -2]]
def initialize(start_position = [0, 0])
@start_position = start_position
build_move_tree(start_position)
end
def new_move_positions(pos)
new_moves =... | true |
40573bbc46e2121b4a76725adae930766454aca9 | Ruby | nerdinand/nnfs-ruby | /09_backpropagation/02_combining_everything.rb | UTF-8 | 2,095 | 3 | 3 | [] | no_license | require 'numo/narray'
require_relative 'layer_dense'
require_relative 'activation_relu'
require_relative 'activation_softmax_loss_categorical_crossentropy'
require_relative '../lib/nnfs'
NNFS.init
require_relative '../lib/datasets'
# Create dataset
x, y = SpiralData.create(n_samples: 100, n_classes: 3)
# Create Den... | true |
8d40e285dbc4cac4f03feaf0cbcb459a3f8b51ae | Ruby | rachelferretto/WDI_16_HOMEWORK | /Rachel/wk04/1-mon/temp_converter.rb | UTF-8 | 947 | 4.1875 | 4 | [] | no_license | require 'pry'
puts('enter a start temp')
temp = gets.chomp.to_i
puts('enter a unit: F, C or K')
unit = gets.chomp
def convert_temp(temp,unit)
if unit == "F"
puts("fahrenheit: #{temp}")
temp = (temp - 32) / 1.8
puts("#{unit} to celcius: #{temp}")
temp = (temp + 459.67) / 1.8
... | true |
c925e5ed3a9b62f4aa76fe92b58eda7174b40d30 | Ruby | Drew242/chisel | /lib/chisel.rb | UTF-8 | 352 | 3.203125 | 3 | [] | no_license | require_relative "string_chunker"
require_relative "chiseler"
class Chisel
attr_reader :input, :output
def initialize
input = File.read(ARGV[0])
html = StringChunker.new(input).html
File.write(ARGV[1], html)
puts "Converted #{ARGV[0]} (#{input.count("\n")} lines) to #{ARGV[1]} (#{html.count("\n")}... | true |
c88953859a56a116535d39d03aa44095a25cbe1a | Ruby | Vince331/http_project | /lib/notes.rb | UTF-8 | 247 | 2.984375 | 3 | [] | no_license | class Notes
def initialize(notes)
@notes = notes
end
def match(matchers)
result = @notes
matchers.select do |elem|
result = result.select do |x|
x.upcase.include? elem.upcase
end
end
result
end
end
| true |
f7729ad7b45079dcbb1df085ccf66629b52ae29d | Ruby | bloomberg/cobbler-cookbook | /libraries/cobbler_parse.rb | UTF-8 | 976 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | module Cobbler
module Parse
include Chef::Mixin::ShellOut
def cobbler_distro(distro, field)
# Parse Cobbler distro report output
# Arguments: distro -- the cobbler distro to get data for
# field -- the field to return
# Acquire Cobbler output like:
# Name ... | true |
3d18a7d2400363be359f10922476def1002754b2 | Ruby | richpeck/vat-mtd | /lib/hmrc.rb | UTF-8 | 3,472 | 2.765625 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | ##########################################################
##########################################################
## __ ____ _______ ______ ##
## / / / / |/ / __ \/ ____/ ##
## / /_/ / /|_/ / /_/ / / ##
## / __ / / ... | true |
4911f0a32a414d92b4a81c93fec91ca8dfcf8750 | Ruby | nkrot/rufsl | /lesson.41/person_age_stub.rb | UTF-8 | 329 | 4.09375 | 4 | [] | no_license | #!/usr/bin/env ruby
class Person
attr_accessor :name
def initialize name, age
@name = name # object variable
@age = age
end
end
alice = Person.new "Alice", 10
bob = Person.new "Bob", 11
puts "Alice older than Bob? " + alice.older_than(bob).to_s
puts "Bob older than Alice? " + bob.older_than(alic... | true |
5deee0894bdaa353b9ae24bebb473837d5b55846 | Ruby | Schwad/assignment_rspec_viking | /spec/bow_spec.rb | UTF-8 | 578 | 3.140625 | 3 | [] | no_license | # Your code here
require 'weapons/bow'
describe Bow do
let (:b) {Bow.new}
describe '#arrows' do
it 'initializes with 10 arrows' do
expect(b.arrows).to eq(10)
end
it 'can initialize with other numbers of arrows' do
expect(Bow.new(3).arrows).to eq(3)
end
end
descr... | true |
c3d6e7f27d94fe193ee483f55c8833db2ea7ef5e | Ruby | AgarwalConsulting/ruby_training | /examples/10-higer-order-functions/mapper_block.rb | UTF-8 | 171 | 3.6875 | 4 | [] | no_license | def mapper(arr, &block)
result = []
for el in arr
res_el = yield el
result << res_el
end
result
end
arr = [1, 2, 3, 4, 5]
pp mapper(arr) { |el| el + 1 }
| true |
a3a8c80c8a5de6158476b62152cac4495712b24d | Ruby | bv4791/PizzaShop_m | /app.rb | UTF-8 | 859 | 2.734375 | 3 | [
"MIT"
] | permissive | #encoding: utf-8
require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require "sinatra/activerecord"
set :database, {adapter: "sqlite3", database: "pizzashop.sqlite3"}
class Product < ActiveRecord::Base
end
class Order < ActiveRecord::Base
end
get '/' do
@products = Product.all
erb :index
end
ge... | true |
53bb7ad4079fdfffb30f381752f5d256288e6a91 | Ruby | Loomus/Fuel_Stations | /app/facades/stations_facade.rb | UTF-8 | 586 | 2.640625 | 3 | [] | no_license | class StationsFacade
def initialize(location)
@location = location
end
def stations
conn = Faraday.new(url: "https://developer.nrel.gov") do |f|
f.params['api_key'] = ENV['nrel_api_key']
f.params['location'] = @location
f.adapter Faraday.default_adapter
end
response = conn.get(... | true |
8174834d3a0274b10df9e8c6e3bbc34faadedaf7 | Ruby | dianajohnson13/toy-problems | /ruby/twoSum.rb | UTF-8 | 416 | 3.921875 | 4 | [] | no_license | # Write a method that takes an array of numbers. If a pair of numbers
# in the array sums to zero, return the positions of those two numbers.
# If no pair of numbers sums to zero, return `nil`.
def two_sum(nums)
contents = {}
nums.each_with_index do |num, i|
if !contents[-num].nil?
return [contents[-n... | true |
c685d4ed8b688c58c1943f2b52766c2cf2b6c1d3 | Ruby | ab-thomas/Inject_and_Takeaway | /Takeaway/spec/Takeaway_spec.rb | UTF-8 | 775 | 2.9375 | 3 | [] | no_license | require 'Takeaway'
describe Takeaway do
let(:takeaway) {Takeaway.new}
context 'Menu'
it 'should have a list of dishes and prices' do
expect(takeaway.menu).to eq(
[{ dish: "Dim Sum", price: 4.99 },
{ dish: "Steamed Rice", price: 2.50 },
{ dish: "Blackbean and Ginger chicken",... | true |
a1729c768f6c6ba4dc3023b61a73791652d16228 | Ruby | ludwiggj/ruby-pickaxe | /ch03-classes-objects-variables/bookshop/example_books/book_in_stock_4.rb | UTF-8 | 403 | 3.671875 | 4 | [] | no_license | class BookInStock4
def initialize(isbn, price)
@isbn = isbn
@price = Float(price)
end
def to_s
"ISBN: #{@isbn}, price: #{@price}"
end
# Explicit accessors
def isbn
@isbn
end
def price
@price
end
# Short code for setters
attr_writer :isbn, :price
end
b1 = BookInStock4.new("... | true |
7f0c8bef2fcf29b79fd3861f2d7bc2683bcb840c | Ruby | micktaiwan/rubymlib | /manager/SQLIActions.rb | ISO-8859-1 | 9,104 | 2.625 | 3 | [] | no_license | # Usage: le fichier emails.txt dans le mme repertoire doit contenir les emails, un par ligne
# TODO:
# - ecrire le last action id en blanc pour pouvoir gnrer des emails et ne pas les envoyer :)
# - pas beau: les dates vides pour les actions closed
# - les actions affiches seules sans classement par group doivent ... | true |
801b93471ecb1815628ee7f5e5249c46c042b9e6 | Ruby | metamorph/tomcat_curl | /tomcat_manager_by_curl.rb | UTF-8 | 2,934 | 2.90625 | 3 | [] | no_license | #!/usr/bin/env ruby
# vim:ai:sw=2:ts=2
# Provides a ruby wrapper for accessing the Tomcat management REST API through Curl.
# The reason for using Curl instead of direct net/http access is to allow this library
# to be used with Capistrano (or net/ssh).
# Interface to create Curl commands agains the Tomcat endpoint.
... | true |
5c79096664c12aefbfefc02bf948a9d8d63086f0 | Ruby | IgnesFatuus/Intro_to_Ruby | /Exercises/Small_Problems/Easy_5/ascii.rb | UTF-8 | 80 | 3.1875 | 3 | [] | no_license | def ascii_value(string)
sum = 0
string.chars { |c| sum += c.ord }
sum
end
| true |
ca6c2920b55d3da62df54b07f1bda6300fa3b04c | Ruby | Lewington-pitsos/launch | /170/sinatra/pad.rb | UTF-8 | 400 | 2.734375 | 3 | [] | no_license | s = "I had seen little of Holmes lately. My marriage had drifted us away
from each other. My own complete happiness, and the home-centred interests
which rise up around the man who first finds himself master of his own
establishment, were sufficient to absorb all my attention, while Holmes,
who loathed every form of... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.