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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
76330fd7f64611e6defa9138fd90ed02daba1697 | Ruby | mattmalane/ruby_small_problems | /easy_4/short_long_short.rb | UTF-8 | 288 | 3.375 | 3 | [] | no_license | def short_long_short(str1, str2)
arr = [str1, str2]
arr2 = arr.sort_by do |str|
str.size
end
arr2[0] + arr2[1] + arr2[0]
end
short_long_short('abc', 'defgh') == "abcdefghabc"
short_long_short('abcde', 'fgh') == "fghabcdefgh"
short_long_short('', 'xyz') == "xyz" | true |
fc1fceed242c7253de5d9b66f4884870c35eab99 | Ruby | srijondasgit/drawstories | /cbse/class7/English1/chapter5.rake | UTF-8 | 1,589 | 2.5625 | 3 | [] | no_license | desc "TODO"
task chappter_one: :environment do
# Chappter.delete_all
# Book.delete_all
# Section.delete_all
# Question.delete_all
book = Book.new(school_id: 1, name: 'Book', author: 'FRANK FLYNN', book_type: 'General')
if book.save
chappter = Chappter.create(book_i... | true |
751a74ed3f136f6f9133d1f30fd72e0483b810ba | Ruby | andie5/assignment_sinatra_basics | /rps_game.rb | UTF-8 | 1,131 | 3.671875 | 4 | [] | no_license | # Create a Rock-Paper-Scissors game, where you choose an option via radio button, submit your choice, and are redirected to an end screen where you see whether you won or lost vs the AI.
# ./app.rb
require 'sinatra'
get '/user_choice_form' do
erb :user_choice_form
end
post '/game_result' do
# Grab the data we ... | true |
ded0ae58d1ff342bf3354236daafe10b94beb1e2 | Ruby | codenamev/advent-of-code | /2020/03.rb | UTF-8 | 400 | 3.171875 | 3 | [] | no_license | # frozen_string_literal: true
TREE = "#"
trees = 0
position = 0
def tree_at?(line:, position:)
# Extend the map as needed for the current position
line *= (position.to_f / (line.length - 1)).ceil unless position.zero?
line[position] == TREE
end
File.readlines("03-input.txt", chomp: true).each do |line|
trees... | true |
e158a8dc8213fb334a5526072aab16fd46706206 | Ruby | nkhosla91/oo-counting-sentences-nyc-web-082619 | /lib/count_sentences.rb | UTF-8 | 529 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class String
def sentence?
if self.end_with?(".")
p true
else
p false
end
end
def question?
if self.end_with?("?")
p true
else
p false
end
end
def exclamation?
if self.end_with?("!")
p true
else
p false
end
end
de... | true |
32defe98177d68a37c65abed4163fc1dc977dd33 | Ruby | abrown152/root-driving-report-generator | /test/trips_test.rb | UTF-8 | 621 | 3.140625 | 3 | [] | no_license | require "test/unit"
require "../app/drivers.rb"
require "../app/trips.rb"
class TestTrip < Test::Unit::TestCase
def setup
@driver = Driver.new("Dan")
@trip = Trip.new("Dan", "07:15", "07:45", "17.3")
end
def test_log_to_driver
@trip.log_to_driver
assert_equal(@driver.trips.length, 1)
asser... | true |
4a97eaeddf2725257ff6130b40c374c6aaa132f2 | Ruby | scottdover/Toolkit | /tools.rb | UTF-8 | 772 | 3.078125 | 3 | [] | no_license | #!/usr/bin/ruby
CURR_DIR = Dir.pwd
CLASS_DIR = 'classes'
gen_err_message = 'Usage: tools [class]:[method] <arg1> <arg2> <...>'
# Make sure we've got arguments
abort(gen_err_message) if ARGV.length == 0
arguments = ARGV
# Get class_method string
class_method = arguments.shift()
# Make sure we have arguments in cla... | true |
2806fc0e7e51325e9faca7f466265e9d4a28393e | Ruby | vlandham/grocery_grab | /parse_google_places.rb | UTF-8 | 1,531 | 3.09375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'json'
json_filename_pattern = ARGV[0]
output_filename = "locations.tsv"
files = Dir.glob(json_filename_pattern)
jsons = []
files.each do |filename|
puts filename
file_content = File.open(filename, 'r').read
json = JSON.parse(file_content)
jsons << json.flatten
end
puts jsons.s... | true |
2b5c81bafceb867fb0a0013eddd82eeb1de0c053 | Ruby | expajp/Exercism | /ruby/resistor-color-duo/resistor_color_duo.rb | UTF-8 | 477 | 2.84375 | 3 | [] | no_license | class ResistorColorDuo
COLORS = %w(black brown red orange yellow green blue violet grey white)
ACCEPTABLE_COLORS = 2
class << self
def value(color_names)
colors = color_names[0..ACCEPTABLE_COLORS-1].map{ |name| (COLORS.map.with_index{ |color, i| [color, i] }.to_h)[name] }
reversed_powers_of_ten... | true |
b0161a65824031c3dd92cc2f343af5058e0d2678 | Ruby | Thomascountz/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 377 | 3.546875 | 4 | [] | no_license | def add(num_1, num_2)
num_1 + num_2
end
def subtract(num_1, num_2)
num_1 - num_2
end
def sum(array)
(array.reduce :+).to_i
end
def multiply(*args)
(args.reduce :*).to_i
end
def power(num_1, num_2)
num_1**num_2
end
def factorial(num)
sum = num
num = num - 1
while num > 0 do
s... | true |
c3564ba4018a427080223afe55fa96677635a3d6 | Ruby | eee-c/couch_design_docs | /lib/couch_design_docs/design_directory.rb | UTF-8 | 914 | 2.6875 | 3 | [] | no_license | class Hash
def deep_merge(other)
self.merge(other) do |key, oldval, newval|
oldval.deep_merge(newval)
end
end
end
module CouchDesignDocs
class DesignDirectory
attr_accessor :couch_view_dir
def self.a_to_hash(a)
key = a.first
if (a.length > 2)
{ key => a_to_hash(a[1,a.l... | true |
02d84213cf390f68a962151589e70c3573d98f71 | Ruby | ChristopherLazard/ruby_contact_list | /contact_list.rb | UTF-8 | 389 | 3.390625 | 3 | [] | no_license | require 'pry'
require 'colorize'
puts 'Welcome to the contact list.'
puts 'Menu'
puts '1) Show Contacts'
puts '2) Add Contacts'
puts '3) Quit'
contacts = []
user_inpput = gets.to_i
case user_input
when 1
contacts.each do |contact|
puts "Contacts: #{contact}"
end
when 2
puts 'add a new contact'
when 3
puts... | true |
2ef7d423af4c554067eafd6e47243c6fb7419ba5 | Ruby | edwinv710/ElectionMap | /spec/model/contest_spec.rb | UTF-8 | 3,625 | 2.703125 | 3 | [] | no_license | require "spec_helper"
require "contest"
describe Contest do
let(:state) {State.create(name: "New York", symbol: "ny")}
let(:election) {Election.create(name: "Republican Primary", affiliation: "republican", process_type: "primary", year: 2016)}
let(:candidate) {Candidate.create(first_name: "Edwin", last_name: "V... | true |
c39099267167c2a7546658fa763ac090b75e1300 | Ruby | Scott2bReal/LS-ruby-basic-exercises | /return/b_l_or_d_6.rb | UTF-8 | 249 | 4.6875 | 5 | [] | no_license | # What will the following code print? Why?
def meal
return 'Breakfast'
'Dinner'
puts 'Dinner'
end
puts meal
# This will print only 'Breakfast', because the first line of the meal method
# returns, exiting the method before it puts 'Dinner'
| true |
14de5d7bfb00a9dcae003af3afd31b4b688f4e98 | Ruby | marita30/practice_ruby | /chapter8/quiz1/questions/question_1.rb | UTF-8 | 1,061 | 4.28125 | 4 | [] | no_license | # Write a program that calculates the score for a word in Scrabble.
# It should:
# * Ask the user for a word e.g. `apple`.
# * `puts` the score for the word in Scrabble by totalling the points
# for each letter in the word.
# * Points for each letter:
# * 0 points: blank tile
# * 1 point: E, A, I, O, N, R, ... | true |
2efbe3497e393651ef3017542274811717d6442b | Ruby | pierre-1/ruby_exercises | /methods.rb | UTF-8 | 432 | 4 | 4 | [] | no_license | def greeting(name)
"Hi, " + name + ". How's it going?"
end
puts greeting("Pierre")
def add(a, b)
a + b
end
def subtract(a, b)
a - b
end
p add(20, 45)
p subtract(80, 10)
def multiply(num1, num2)
num1*num2
end
p multiply(add(20, 45), subtract(80, 10))
p add(subtract(80, 10), multiply(subtr... | true |
b4ba0db59682953c18466197ea2b6d6e8d3b1f0a | Ruby | wvulibraries/LibManagementTool | /test/models/special_hour_test.rb | UTF-8 | 1,820 | 2.734375 | 3 | [] | no_license | require 'test_helper'
class SpecialHourTest < ActiveSupport::TestCase
def setup
@spec_hour = SpecialHour.find(1)
@spec_hour2 = SpecialHour.find(2)
end
test "special hours are valid" do
assert @spec_hour.valid?, "the special hour is not valid"
end
test "special hour id is a valid integer or is a... | true |
da341f4cab8a1f950fce35e22f2cd96ebcb456c1 | Ruby | Zietieflr/programming-univbasics-4-finding-an-element-in-an-array-lab-den01-seng-ft-051120 | /lib/find_in_array.rb | UTF-8 | 279 | 3.203125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def find_element_index(array, value_to_find)
#array.index(value_to_find);
matching_index = [];
if array.include?(value_to_find)
array.length.times { |index|
if array[index] == value_to_find
return index;
end
}
else
return nil;
end
end
| true |
bdac95342a2011a0b52dfef7adb82d49510aa1ed | Ruby | jhmcstanton/rudder | /lib/rudder/dsl/group.rb | UTF-8 | 3,055 | 3.0625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'set'
module Rudder
module DSL
##
# Concourse group. Logically groups together Concourse
# jobs in the UI.
#
# == DSL Usage:
#
# {Rudder::DSL::Group}'s are the simplest element of any
# Concourse Pipeline, defined by only a name and a non-empty
... | true |
2c356819342d935d753cc1fbe7c2affd27b8e460 | Ruby | ewiener/rabble | /lib/rabble/square.rb | UTF-8 | 1,742 | 3.390625 | 3 | [
"MIT"
] | permissive | module Rabble
class Square
attr_reader :board, :row, :col, :letter_multiplier, :word_multiplier
attr_accessor :letter
def initialize(board, row, col, opts = {})
@board = board
@row = row
@col = col
@letter_multiplier = opts[:letter_multipler] || 1
@word_multiplier = opts[:wo... | true |
3b3608a6c2ad927c7f9900cd83119d8ba0f0dd88 | Ruby | clyeager/intro-to-programming | /chapter5_loops_and_iterators/exercise2.rb | UTF-8 | 124 | 3.3125 | 3 | [] | no_license | puts "What can i do for you?"
input = gets.chomp
while input != "STOP"
puts input + " you say?"
input = gets.chomp
end
| true |
7975f3e1c4157ed27317f4fa4a07b096dcd8d507 | Ruby | ayrtonaoki/estudo_tdd | /spec/matchers_verdadeiro_falso_spec.rb | UTF-8 | 662 | 2.90625 | 3 | [] | no_license | describe 'Matchers Verdadeiro ou Falso' do
context '#true' do
it 'Testa se é verdadeiro' do
expect(1.odd?).to be true
end
end
context '#be_truthy (mesma função do #true)' do
it 'Testa se é verdadeiro' do
expect(1.odd?).to be_truthy
end
end
... | true |
8d1d873fcc03e3e1f2bd8e789abcdd6be7373e92 | Ruby | danjungo/danjungo | /hpricot/hp12/app/controllers/demo_controller.rb | UTF-8 | 1,574 | 2.578125 | 3 | [] | no_license | # This is a demo controller
require 'rubygems'
require 'hpricot'
require 'open-uri'
class DemoController < ActionController::Base
# Open this controller to the world
skip_before_filter :authenticate_usr
# I help Hpricot
Hpricot.buffer_size = 262144
# Null out the parse() method of WebAgent::CookieManager... | true |
9b0d740e7bff937b8b5fac2c0d4404dea663f921 | Ruby | Petermuturi/bloacks-and-procs | /something.rb | UTF-8 | 326 | 3.234375 | 3 | [] | no_license | def doSelfImportantly someProc
puts 'Everybody just HOLD ON! I have something to do...'
someProc.call
puts 'Ok everyone, I\'m done. Go on with what you were doing.'
end
sayHello = Proc.new do
puts 'hello'
end
sayGoodbye = Proc.new do
puts 'goodbye'
end
doSelfImportantly sayHello
doSelfImportantly sayGood... | true |
3451ecc857a51edace136694d076fb6671aa0a43 | Ruby | LukVik/helloword | /app/models/hw_branching.rb | UTF-8 | 1,028 | 4.5625 | 5 | [] | no_license | def multiply(first_num, second_num)
first_num.to_f * second_num.to_f
end
def divide(first_num, second_num)
first_num.to_f / second_num.to_f
end
def add(first_num, second_num)
first_num.to_f + second_num.to_f
end
def substract(first_num, second_num)
first_num.to_f - second_num.to_f
end
def mod(first_num, sec... | true |
49d0c047c09b5f6a89659e549438e1fba2337b61 | Ruby | milodky/test_app | /app/models/micropost.rb | UTF-8 | 1,270 | 2.65625 | 3 | [] | no_license | class Micropost < ActiveRecord::Base
DEFAULT_PER_PAGE = 10
belongs_to :user
# The way to tell CarrierWave to associate the image with a model is to use the
# mount_uploader method, which takes as arguments a symbol representing the
# attribute and the class name of the generated uploader
mount_uploader :pic... | true |
1ddbe30c785885cbf29b8ddd1a21f43f87328755 | Ruby | ivoputzer/refactoring-exercise | /unit.rb | UTF-8 | 2,051 | 2.625 | 3 | [] | no_license | Dir.entries("task").each { |file| require "./task/#{file}" unless file =~ /^\.+$/ }
require "test/unit"
class UnitTest < Test::Unit::TestCase
def test_a_single_movie
customer = Customer.new :Ivo
rental1 = Rental.new (Movie.new :Armageddon, Movie::REGULAR), 5
customer.add_rental rental1
... | true |
1fa25f2ce72323d1fdf7d406cde0f0e07ff506e8 | Ruby | davetron5000/bookdown | /lib/bookdown/directives/commands/method_call.rb | UTF-8 | 467 | 2.625 | 3 | [] | no_license | require_relative "base_command"
class Bookdown::Directives::Commands::MethodCall < Bookdown::Directives::Commands::BaseCommand
attr_reader :object, :method, :argument
def initialize(object,method,argument)
@object = object
@method = method
@argument = argument
end
def execute(_current_output_i... | true |
4f1b18fea93f016b745f3ac284c8b211fd7e56c3 | Ruby | jonas-masharqa/fizz_buzz | /review_reflect.rb | UTF-8 | 505 | 3.78125 | 4 | [] | no_license | # 1. Flow control is conditiinals and loops that alter the flow
# of a Ruby program. If statements, while loops, case expressions
# etc are all part of the flow control.
# 2. We could use 'unless'
# 3. Modulo divides the left hand operand by the right hand
# operand and gives us the remainder. If there is any.
# For ... | true |
ce787a717c12dd6d02b64967223cce4a5e642721 | Ruby | deep-cover/deep-cover | /core_gem/lib/deep_cover/node/mixin/can_augment_children.rb | UTF-8 | 2,210 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module DeepCover
module Node::Mixin
module CanAugmentChildren
def self.included(base)
base.has_child_handler('remap_%{name}')
base.singleton_class.prepend ClassMethods
end
# Augment creates a covered node from the child_base_node.
# Caution: ... | true |
46e14391b21eaf5f8f80e16502ac455dff934f2b | Ruby | stangel/memcache | /lib/memcache/segmented.rb | UTF-8 | 3,472 | 2.609375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'digest/sha1'
class Memcache
module Segmented
MAX_SIZE = 1000000 # bytes
PARTIAL_VALUE = 0x40000000
def get(keys, cas = nil)
return get([keys], cas)[keys.to_s] unless keys.kind_of?(Array)
return {} if keys.empty?
results = super(keys, cas)
keys = {}
keys_to_fetch =... | true |
8c9b1272ee2f14f2fb6523d3a1c16425792dd1d3 | Ruby | GideonJa/Euler | /gid_17.rb | UTF-8 | 1,237 | 3.859375 | 4 | [] | no_license | # p "three hundred and forty-two".gsub(/[\s-]/,'')
def to_human(num)
word={}
word[0] = "zero"
word[1] = "one"
word[2] = "two"
word[3] = "three"
word[4] = "four"
word[5] = "five"
word[6] = "six"
word[7] = "seven"
word[8] = "eight"
word[9] = "nine"
word[10] = "ten"
word[11] = "eleven"
word[12] ... | true |
10745b5cfb12b4f4591c7fe24e28628a228863bf | Ruby | ChrstphGrnr/regex-lab-online-web-ft-021119 | /lib/regex_lab.rb | UTF-8 | 459 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def starts_with_a_vowel?(word)
word.scan(/\A[aeiouAEIOU]/).length == 0 ? false : true
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/un\w*ing/)
end
def words_five_letters_long(text)
text.scan(/\b\w{5}\b/)
end
def first_word_capitalized_and_ends_with_punctuation?(text)
text.... | true |
8046fe82599032fb2259281a537caf64a4ec97b0 | Ruby | hikaen2/ttf-bdfumplus-outline | /bin/bdfuniq | UTF-8 | 338 | 2.78125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unicode",
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# bdfuniq
# uniq by ENCODING
#
# Created by hikaen2 on 2019-10-22
# Licenced under the MIT license
#
bdf = STDIN.read
chars = bdf.scan(/STARTCHAR.+?ENDCHAR\s*\n/m).uniq {|s| s[/ENCODING\s+(\d+)/, 1].to_i}
print(bdf[/^.*?ENDPROPERTIES\s*\n/m])
print("CHARS %d\n" % chars.length)
print(chars.join)
p... | true |
d38b19c36676c04c2df7965b81b426840ca0f5c3 | Ruby | glebson1988/somerubyalgo | /even_fibonacci_number_algorithm.rb | UTF-8 | 470 | 4.1875 | 4 | [] | no_license | # By considering the terms in the Fibonacci sequence whose values
# do not exceed four million, find the sum of the even-valued terms.
class Fibbing
def initialize(max)
@num_1 = 0
@i = 0
@sum = 0
@num_2 = 1
@max = max
end
def even_fibonacci
while @i <= @max
@i = @num_1 + @num_2
... | true |
ff92b199410a68c0515524b07f5224f9234c8c3f | Ruby | conwqi1/DailyCodeAppAcademy | /w1d1/02_common_substrings.rb | UTF-8 | 379 | 3.453125 | 3 | [
"MIT"
] | permissive | def common_substrings(str1, str2)
length = str1.length
subtrings = []
length.times do |start_position|
(1...length - start_position).each do |sub_length|
subtring = str1[start_position..start_position+sub_length]
subtrings << subtring if str2.include?subtring
end
end
subtrings.max_by(&:lengt... | true |
ac4b67491cd88018e199935900ab8465e02adb85 | Ruby | pbbrown1112/intro-to-simple-array-manipulations-houston-web-051319 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 844 | 3.640625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_push(array, string)
array.push(string)
array
end
def using_unshift(array, string)
array.unshift(string)
array
end
def using_pop(array)
last_item = array.pop()
last_item
end
def pop_with_args(array)
last_items = array.pop(2)
last_items
end
def using_shift(array)
first_item = array.shift()... | true |
e1dc9ff7e8679b1d96e2d6dcdc7ab89f162968a2 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/simple-cipher/c32d03e7f23f44e088898fce23845ab2.rb | UTF-8 | 862 | 3.34375 | 3 | [] | no_license | class Cipher
attr_reader :key
def initialize(key = default_key)
validate_key(key)
@key = key
end
def default_key
"dddddddddd"
end
def encode(string)
convert_string(string, :encode_char)
end
def decode(string)
convert_string(string, :decode_char)
end
private
def validate_k... | true |
b6e49151469724b08fd15d8b2c2e2310cfd16a7c | Ruby | nahrivera7/HackerRank---30-days-challenge | /day20.rb | UTF-8 | 408 | 3.625 | 4 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
# Write Your Code Here
counter = 0
i = 0
while i < n
j = 0
while j < (n-1)
if a[j] > a[j+1]
a[j], a[j+1] = a[j+1], a[j]
counter += 1
end
j += 1
end
if counter == 0
break
end
i += 1
end
puts "Array is ... | true |
eb30229ade4ebfae8e83742916c5b0246f65c6c1 | Ruby | brickstar/night_writer | /lib/night_write.rb | UTF-8 | 315 | 3.1875 | 3 | [] | no_license | require "./lib/night_writer"
message = File.open('./lib/message.txt', 'r')
input = message.read
message.close
nw = NightWriter.new
braille = File.new('./lib/braille.txt', 'w')
braille.puts(nw.output(input))
puts "Created 'braille.txt' containing #{nw.braille_string.delete("\n").length} characters"
braille.close
| true |
c53b922dbc43b115bcd48e7ace69012fe5df8337 | Ruby | Milaap/easy_rails_money | /lib/easy_rails_money/active_record/migration/table.rb | UTF-8 | 5,096 | 2.75 | 3 | [
"MIT"
] | permissive | module EasyRailsMoney
module ActiveRecord
module Migration
module Table
# called for change_table
# currency and #money defined in TableDefinition
# Creates one or two columns to represent a Money object in the named table
#
# An integer column for storing Money in i... | true |
877b056785aba70eb8c72f5f42df0211d63eaffd | Ruby | michdsouza/SalesTax | /lib/product.rb | UTF-8 | 422 | 3.625 | 4 | [] | no_license | class Product
ROUNDING_TO = 0.05
def initialize(description, price, tax)
@description = description
@price = price
@tax = tax
end
def format_description
return @description
end
def price_with_tax
return ("%.2f" %(@price + calculate_tax)).to_f
end
def calculate_tax
raw_tax = @... | true |
2bbd8b86eae7d8f871ea92aed23431ce8fc9ac8f | Ruby | NavdeepAVV/RubyProj | /Navdeep_Assignment/test_spec.rb | UTF-8 | 857 | 2.703125 | 3 | [] | no_license | require 'rspec'
require_relative './LineAnalyzer'
require_relative './Solution'
describe LineAnalyzer do
before { @lineAnalyzer = LineAnalyzer.new("aa aa b", 1)}
it "should give highest frequency of words" do
expect(@lineAnalyzer.calculate_word_frequency()).to eq 2
end
#LineAnalyzer.new("aa aa... | true |
6f98795594bde08df172788599f58c8674be24b9 | Ruby | Juan1808/EjerciciosRails | /CursoRuby/src/_14_mixin/Datos.rb | UTF-8 | 206 | 2.515625 | 3 | [] | no_license | #Mediante la palabra 'include' podemos incluir otras librerias
class Datos
include Imprimible
attr_reader :valor1,:valor2
def initialize valor1,valor2
@valor1,@valor2 = valor1,valor2
end
end | true |
7cdcd9ba8acbf37582072c5da5a0dbaf6caf348b | Ruby | parshap/csv_parser | /test.rb | UTF-8 | 2,186 | 3.234375 | 3 | [] | no_license | require "test/unit"
require "csv"
require_relative "lib/csv_parser"
class SimpleParser < CSVParser
attr_reader :called
attr_reader :once_called
attr_reader :first_called
def initialize(csv)
@called = 0
@once_called = 0
@first_called = 0
super
end
parse String do |val, key|
@called += ... | true |
f27d19d8a1a677268149ad5415be70845633c475 | Ruby | daimyo-college/ruby-super-intro-lesson | /yazawa8/chapter7/7-5.rb | UTF-8 | 92 | 2.859375 | 3 | [] | no_license | def order(drink)
p "#{drink}をください"
end
drink = "コーヒー"
order(drink) | true |
1b075dc6c99079f5ce07bfb75586acdac3cd260b | Ruby | rayning0/ctci | /leetcode/most_common_word.rb | UTF-8 | 486 | 3.34375 | 3 | [] | no_license | # @param {String} paragraph
# @param {String[]} banned
# @return {String}
def most_common_word(paragraph, banned)
freq = Hash.new(0)
mostfreqword = ''
maxfreq = 0
paragraph = paragraph.downcase.gsub(/[!?',;.]/, ' ')
paragraph.split.each do |word|
freq[word] += 1
end
freq.each do |wo... | true |
ecad62afc086359785063b6f332079d9615c243d | Ruby | gulazaro94/znns | /app/reports/survivors_percentage_report.rb | UTF-8 | 534 | 2.96875 | 3 | [] | no_license | class SurvivorsPercentageReport
INFECTED_PERCENTAGE_SQL = '
COUNT(*) AS total,
COUNT(*) FILTER (where infected IS TRUE) AS infected_quantity
'.squish
def initialize(infected:)
@infected = infected
end
def calculate_infected_percentage
result = Survivor.select(sql).load.first
(result.inf... | true |
b6e25b36892c6665a9c82d2b63d45a06e0363604 | Ruby | skandow/binary-search-tree-chi01-seng-ft-051120 | /binary_search_tree.rb | UTF-8 | 596 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class BST
attr_reader :data, :left, :right
def initialize(data)
@data = data
@left = nil
@right = nil
end
def insert(new_key)
if new_key <= self.data
@left.nil? ? @left = BST.new(new_key) : @left.insert(new_key)
elsif new_key > self.data
... | true |
970aed1e07fcca5b71f61199240d0e5af1188628 | Ruby | DouglasAllen/code-Metaprogramming_Ruby | /raw-code/PART_II_Metaprogramming_in_Rails/gems/camping-1.5/lib/camping/session.rb | UTF-8 | 5,108 | 3.15625 | 3 | [
"MIT"
] | permissive | #---
# Excerpted from "Metaprogramming Ruby: Program Like the Ruby Pros",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for ... | true |
f36c6ffb0bdaf3f264e52470218504e4e1eee9d5 | Ruby | carlyayres/admin_exercise | /are_you_cool/are_you_cool.rb | UTF-8 | 345 | 4.40625 | 4 | [] | no_license | require "pry"
def are_you_cool(location)
if location == "manhattan"
puts("no")
elsif location == "brooklyn"
puts("v cool v cool")
else
puts ("nah")
end
end
# ask the user for a string
puts "Yo where u live?"
# store the users input in a variable
user_location = gets.strip
# call the method
are... | true |
3d5156bd376d1bf83808f5599098380e3b9ea4b0 | Ruby | fifiteen82726/coda-chain | /app/lib/test.rb | UTF-8 | 221 | 2.671875 | 3 | [] | no_license | class Test < Block
end
# Print the block information
# t = Test.new(1,2,3,4)
# t.explain
# Create first block
# t = Test.genesis
# t.explain
# Create the next block
t = Test.mine_block(Test.genesis, '12312')
t.explain
| true |
b827288249665ed88b6f01ff2187bdc8d33a291c | Ruby | mixtli/netatlas-client | /lib/netatlas/renderer/table.rb | UTF-8 | 1,425 | 2.609375 | 3 | [
"MIT"
] | permissive | module NetAtlas::Renderer
class Table
include CommandLineReporter
def initialize(data, *args)
@data = data
@headers = args.map do |arg|
if arg.kind_of?(Hash)
arg[:label] ||= arg[:field].to_s
arg
else
{:field => arg, :label => arg.to_s}
end
... | true |
cdd5d15d9601bf7e7e856434b9481815903985e0 | Ruby | gegerlan/Gentle-Love-Quest | /Source/Scripts/Sprite_Base.rb | UTF-8 | 7,481 | 2.796875 | 3 | [] | no_license | #==============================================================================
# ** Sprite_Base
#------------------------------------------------------------------------------
# A sprite class with animation display processing added.
#==============================================================================
cla... | true |
10a092d4dbd0e7312fc17ae930322a843705624b | Ruby | RichWork/Learn-Ruby-the-hard-way | /less25/ex25.rb | UTF-8 | 2,324 | 4.5625 | 5 | [
"MIT"
] | permissive | module Ex25
# This function will break up words for us.
# The .split(' ') is splitting the sentence on the ' ', e.g. spaces
# Note that it outputs multiple values which requires a variable to capture
def Ex25.break_words(stuff)
words = stuff.split(' ')
return words
end
# Sorts the words.... | true |
44a3e7386cf4c33df3d3ca1bc334fa38a630d1ef | Ruby | AlanGibsonCivica/coding-challenges | /Challenge 1/Ruby/main.rb | UTF-8 | 214 | 3.53125 | 4 | [] | no_license |
TESTS = [
'HELLO WORLD',
'SOMETHING ELSE',
'ABCDEFG'
]
for test in TESTS do
result = find_repeat_character(test)
puts "#{test} : #{result}"
end
BEGIN {
def find_repeat_character(input)
end
}
| true |
47f7df5d7a73873588b5abb9045d4cab834cd8e5 | Ruby | filip373/ruby_algorithms | /spec/enumerable_spec.rb | UTF-8 | 2,577 | 3.359375 | 3 | [] | no_license | require './enumerable'
describe Enumerable do
describe '.my_each' do
context 'when used on non-empty array' do
it 'iterates all elements' do
output = []
(1..5).to_a.my_each { |e| output << e }
expect(output).to eql((1..5).to_a)
end
end
context 'when used on empty ar... | true |
c4fc53c7dcf3b874e26f8a806ab33e1d785adfa4 | Ruby | emperorliu/tealeaf-precourse | /04_Flow_Control/05.rb | UTF-8 | 825 | 4.46875 | 4 | [] | no_license |
def evaluate(num)
case
when num < 0
puts "You can't put a negative number!"
when num <= 50
puts "#{num} is between 0 and 50"
when num <= 100
puts "#{num} is between 50 and 100"
else
puts "#{num} is above 100"
end
end
def evaluate2(num)
if num < 0
puts "You can't put a negative number!"
elsif num <= ... | true |
cc8d874070f291d1e29b352893e5032911dc79ae | Ruby | vromero2017/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 2,111 | 4.3125 | 4 | [] | no_license | # Ruby's simple Calculator
# Addition Method
def sum(num1)
sum = num1
loop do
number2 = gets.chomp.to_i
sum = sum + number2.to_i
puts "----"
puts sum
op = gets.chomp
operator(op,sum)
end
end
# Subtraction Method
def dif(num1)
dif = num1
loop do
... | true |
437f043fc26151480a84a680610c7861d6256b9f | Ruby | hubbardgary/AdventOfCode2016 | /day24.rb | UTF-8 | 4,461 | 3.578125 | 4 | [
"MIT"
] | permissive | # --- Day 24: Air Duct Spelunking ---
#
# You've finally met your match; the doors that provide access to the roof are locked tight, and all of the controls
# and related electronics are inaccessible. You simply can't reach them.
#
# The robot that cleans the air ducts, however, can.
#
# It's not a very fast little rob... | true |
38872aa92fe3b160ad71e321888b94dbc1d0ee6d | Ruby | inabaakira/practice_book_head_first_ruby | /chap13/test/test_array.rb | UTF-8 | 459 | 3 | 3 | [] | no_license | #!/usr/bin/env ruby
#-*- mode: ruby; coding: utf-8 -*-
# file: test_array.rb
# Created: <2017/12/12 21:25:44>
# Last Modified: <2017/12/12 21:29:35>
require 'minitest/autorun'
class TestArray < Minitest::Test
def setup
@array = ['a', 'b', 'c']
end
def test_length
assert_equal(3, @array.leng... | true |
1086124705431f1b17d11a9263e5dccfc8ed3010 | Ruby | juanccamachob94/dictionary | /main.rb | UTF-8 | 318 | 3.359375 | 3 | [] | no_license | load 'word.rb'
load 'dictionary.rb'
apple = Word.new('apple', 'A fruit')
puts apple.name?('apple')
puts apple.meaning?('A fruit')
car = Word.new('car', 'A transport')
dictionary = Dictionary.new([apple, car])
puts dictionary.find_meaning('apple') == 'A fruit'
puts dictionary.find_meaning('car') == 'A transport'
| true |
cf5b65759459789dbb247ca330d7bf210ca12c0e | Ruby | Maimer/ruby_racer | /Ruby Racer.app/Contents/Resources/lib/chingu/game_object_map.rb | UTF-8 | 6,254 | 3.078125 | 3 | [] | no_license | #--
#
# Chingu -- OpenGL accelerated 2D game framework for Ruby
# Copyright (C) 2009 ippa / ippa@rubylicio.us
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.... | true |
6e1977498f362507e43cd91cdf61bf346b000588 | Ruby | ACLTearr/Rocket-Elevators-Ruby-Controller | /residential_controller.rb | UTF-8 | 13,495 | 2.984375 | 3 | [] | no_license | module ResidentialController
#Defining column class
class Column
def initialize(id, status, amountOfElevators, amountOfFloors)
@ID = id
@status = status
@amountOfElevators = amountOfElevators
@amountOfFloors = amountOfFloors
@elevatorsList = []... | true |
bf79cee3ebdfd1d3b1cc8529be3e45fc202e8d14 | Ruby | AravindhAjju/Student-Class-Report | /app/models/scorecard.rb | UTF-8 | 584 | 2.59375 | 3 | [] | no_license | class Scorecard < ApplicationRecord
belongs_to :student, inverse_of: :scorecard
has_many :subject_scores, dependent: :destroy, inverse_of: :scorecard
validates_length_of :subject_scores, is: 4, wrong_length: "Need %{count} score entries"
accepts_nested_attributes_for :subject_scores
before_save :set_total
... | true |
0e5d81f655cf39ce8326c964a87154a440517907 | Ruby | michaelscotthurley/ruby-rio-grande | /starter-code/spec/digitalitem_spec.rb | UTF-8 | 2,042 | 3.046875 | 3 | [] | no_license | require_relative 'spec_helper'
require_relative '../lib/DigitalItem'
describe DigitalItem do
before(:context) do
@digitalitem = DigitalItem.new("Generic Digital Item",1.99)
end
describe "Initialization" do
it "is an instance of the Digital Item class" do
expect(@digitalitem).to be_instance_of(Dig... | true |
da346059960bf594cf7602459de07c3b7e76790f | Ruby | shukerski/ruby-retrospective-4 | /solutions/02.rb | UTF-8 | 292 | 3.5 | 4 | [] | no_license | class NumberSet
include Enumerable
def initialize()
@numbers = []
end
def each(&block)
@numbers.each(&block)
end
def <<(number)
@numbers << number unless @numbers.include? number
end
def size
@numbers.size
end
def empty?
@numbers.empty?
end
end | true |
c433e23c6925c3cc1febc9f05252ee0cb6922819 | Ruby | valedithat/hackerrank | /simple_array_sum.rb | UTF-8 | 876 | 4.03125 | 4 | [] | no_license |
# Given an array of integers, find the sum of its elements.
# For example, if the array , , so return .
# Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.
# simpleArraySum has the following parameter(s):
# ar: an array of integers
# The first line... | true |
6cfff22b82b51a1b1570d3f42cb219d389229877 | Ruby | musgravejw/euler | /25/20.rb | UTF-8 | 199 | 3.515625 | 4 | [] | no_license | n = 0
sum = 0
def factorial(n)
total = 1
for i in 1..n
total *= i
end
return total
end
n = factorial(100)
while n > 0
i = n % 10
sum += i
n /= 10
end
puts sum | true |
c2b14ac33708fd6a23c65a859a74d008aeb22dc3 | Ruby | will-wow/kablammo-scaredy-bot | /lib/scaredy/danger_matrix.rb | UTF-8 | 1,043 | 3.265625 | 3 | [
"MIT"
] | permissive | require "matrix"
require "kablammo"
require_relative "./cell"
require_relative "./danger_score"
module Scaredy
class DangerMatrix
include Strategy::Constants
attr_accessor :matrix
def self.score(board, me, opponents)
danger_matrix = DangerMatrix.new()
danger_matrix.score_cells(me, board, o... | true |
f3933571cf155422a6554ad5d68d43a3439dee76 | Ruby | bbz-biel-informatik/sqlviz | /lib/tasks/anderhalden.rake | UTF-8 | 1,364 | 2.546875 | 3 | [] | no_license | require 'open-uri'
require 'json'
require 'pg'
require 'ostruct'
desc "Load data from fvbj into the database"
namespace :anderhalden do
desc 'Create the necessary tables'
task :prepare do
sql = File.read(File.join(File.dirname(__FILE__), 'anderhalden.sql'))
db = PG::Connection.new(ENV['DATABASE_URL'])
... | true |
5c9aae8c1d6bb13e9b36c4f3267641b7f73a1324 | Ruby | oscar6654/spree_import | /app/models/spree/import_product.rb | UTF-8 | 738 | 2.53125 | 3 | [
"MIT"
] | permissive | module Spree
class ImportProduct
attr_accessor :name, :weight, :weight_units, :description, :height, :width, :depth,
:qty, :price, :cost_price, :slug, :sku, :meta_description, :update_slug,
:meta_title, :cost_currency, :image_src, :image_alt, :store, :shipping
def initia... | true |
88d0800a553dd57e53164b06e94c4c39550d4f69 | Ruby | osyrak/ruby_learn | /peremennye.rb | UTF-8 | 65 | 2.59375 | 3 | [] | no_license | name = " Zigmundus "
surname = " Kakatus "
puts name + surname
| true |
443f97fc88695267d473e213ac25553dee0b6409 | Ruby | blablauser/exam | /lib/question_paper.rb | UTF-8 | 341 | 3.078125 | 3 | [] | no_license | class QuestionPaper
attr_reader :questions
def initialize
@questions=[]
end
def questions
return @questions
end
def add(question)
@questions.push(question)
end
def total_marks
sum=0
@questions.each do | question |
sum = sum + question.mark
end
sum
end
def availabl... | true |
02fc88e25037411abfedda8f856ebfc49a8896f6 | Ruby | yoshioteruia/credit_card_validator | /spec/credit_cards_validator_spec.rb | UTF-8 | 1,134 | 2.734375 | 3 | [] | no_license | require 'rspec'
require_relative '../lib/credit_cards_validator'
describe CreditCardsValidator do
it 'prints a list of credit cards' do
credit_card_numbers = <<-EOL
4111111111111111
4111111111111
4012888888881881
378282246310005
6011111111111117
5105105105105100
5105 105... | true |
36215ca8e4993e844d5db01e5b51591fe4163295 | Ruby | Prateek057/Pl-Ruby | /a.rb | UTF-8 | 955 | 3.25 | 3 | [] | no_license | class Car
def initialize(regno, color)
@regno = regno
@color = color
@@car_props = {
@regno => @color
}
end
end
class ParkingLot < Car
def initialize
@no_of_slots=0
@slots=Array.new
end
def create n
... | true |
8496ab8ac62e9fdcd95ce719145b74cace8233c5 | Ruby | ben2d2/NSS-Cal | /test/test_cal.rb | UTF-8 | 1,887 | 3.265625 | 3 | [] | no_license | require 'test/unit'
require 'lib/cal'
class CalendarTest < Test::Unit::TestCase
def test01_is_leap_year
cal = Calendar.new(2, 2011)
assert_equal(false, cal.is_leap_year?)
end
def test01a
cal = Calendar.new(2, 2012)
assert_equal(true, cal.is_leap_year?)
end
def tes... | true |
abfb2caa6b081cb4f5b04933ec11edffbc9475e3 | Ruby | kmcphillips/secret_santa | /spec/secret_santa/person_spec.rb | UTF-8 | 1,157 | 2.671875 | 3 | [
"MIT"
] | permissive | require "spec_helper"
describe SecretSanta::Person do
let(:exchange){ SecretSanta::Exchange.new }
let(:name){ "Fin T. Human" }
let(:email){ "fin@ooonet.com" }
let(:id){ 123 }
let(:person) do
p = SecretSanta::Person.new(name: name, email: email, id: id)
exchange.add_person p
p
end
describe "#... | true |
df933a3b50c7aaf00b6f1770779d7b483c623f77 | Ruby | matthewhenderson/FreqReport | /freqreport.rb | UTF-8 | 6,172 | 3.203125 | 3 | [] | no_license | #*************************************
# Author: Matthew Henderson
# Created: 2012-04-05
#
# The purpose of this script is to get all the fields in a database,
# then, look at the distinct values appearing in that field.
# Once that is done, the frequency each value occurs is calculated.
# A bar graph is produc... | true |
4dda827ece1a30e9899899e9c947eb01805bbdcd | Ruby | TwilioDevEd/automated-survey-rails | /lib/find_next_question.rb | UTF-8 | 578 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | class FindNextQuestion
def self.for(question)
new(question).find_next
end
def initialize(question)
@question = question
end
def find_next
question_id = next_question_id
if question_id
Question.find(question_id)
else
Question::NoQuestion
end
end
private
attr_reader... | true |
51469b18c6bc6971b8f1cdfb53dd3a3bd44592e1 | Ruby | epinczinger/ror-social-scaffold | /spec/models/user_spec.rb | UTF-8 | 2,830 | 2.53125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
context 'Associations' do
it 'does have association with friendships model' do
association = User.reflect_on_association(:friendships)
expect(association.macro).to eq(:has_many)
end
it 'does have association with post model' do
... | true |
1396663e1ca76645da00e8e60a2c35a7e0417b44 | Ruby | mewlist/workaholic | /lib/workaholic/worker.rb | UTF-8 | 1,300 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'thread'
class Workaholic
class RunningError < StandardError; end
attr_reader :queue
attr_reader :state
attr_reader :running
def initialize
@queue = Queue.new
@state = :stopped
@threads ||= []
@running = 0
end
def start( thread_count = 2 )
raise RunningError unless state == ... | true |
1f1e037aa4b3cb38168cd346f4c5ce7688564976 | Ruby | tsellers1990/Ruby_Madlibs | /madlibs.rb | UTF-8 | 880 | 3.359375 | 3 | [] | no_license | puts "Enter a Name"
name_1 = gets.chomp()
puts "Enter a different Name"
name_2 = gets.chomp()
puts "Enter a Fluid"
fluid_1 = gets.chomp()
puts "Enter an Action"
action_1 = gets.chomp()
puts "Enter an Object"
object_1 = gets.chomp()
puts "Enter a Place"
place_1 = gets.chomp()
puts "Enter a Fluid"
fluid_2 = gets.chomp()
... | true |
5ac282a6e5de2a18afeba1a47200a39b567b3d79 | Ruby | CodingAnarchy/activity_generator | /lib/activity_generator.rb | UTF-8 | 3,057 | 2.921875 | 3 | [
"MIT"
] | permissive | require "activity_generator/version"
require "activity_generator/setup"
require "activity_generator/logging"
require "activity_generator/process_handler"
require "activity_generator/process_data"
require "activity_generator/process"
require "activity_generator/file_activity"
require "activity_generator/network_activity... | true |
8790834ec224709ab8d0019ebffd6b6af343e7ed | Ruby | AndriiBuhalo/rubyrush | /gallows/visilitsa.rb | UTF-8 | 973 | 3.25 | 3 | [] | no_license | require_relative "methods"
clear_windows
puts "Ігра вилелиця версія 1"
letters = get_letters #набір слова для ігри
errors = 0 # перевірка на помилки
bad_letters = [] # букви які були помилкові
good_letters = [] # букви які підходили
while errors < 7 do # в циклі водимо нові букви і умови
print_status(letters,... | true |
035c301451c9796cb63dcd7b01f9b9c6a8624fa1 | Ruby | richrace/escapezeta | /spec/rooms/mess_hall_spec.rb | UTF-8 | 735 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
require 'rooms/mess_hall'
describe MessHall do
before(:each) do
@room = MessHall.new
end
describe "#initialize" do
it "will have Mess Hall set as it's name" do
@room.name.should eq "Mess Hall"
end
it "will have the correct contents" do
@room.items.should... | true |
ea5c9f230dff37ce1c4a7fce039efb9b3df1fb57 | Ruby | trevorwhitney/skin-track-basestation | /serial.rb | UTF-8 | 1,263 | 2.8125 | 3 | [] | no_license | require 'serialport'
require 'active_record'
if ARGV.size != 1
abort("Invalid argument, please provide port")
end
port_str = ARGV[0]
baud = 57600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
record_count = 0
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3',
:database => 'db_s1.sqlite'})
... | true |
646fbd6684c0b4a97011201daba72c1fcd93073e | Ruby | beckyrussoniello/pingdom_api_client | /lib/pingdom_api_client/check.rb | UTF-8 | 1,953 | 2.640625 | 3 | [] | no_license | module PingdomApiClient
class Check
include PingdomApiClient::Helpers
attr_accessor :client, :name, :host, :type, :paused, :resolution, :pingdom_id,
:sendnotificationwhendown, :sendtoemail
def initialize(client, options = {})
@client = client
options.each do |key, value|
eval "@#{key} = value if ... | true |
9551e915ae679448b6bf0b18615071e1d6cc1bc7 | Ruby | saadbinakhlaq/algorithms_in_ruby | /remove_duplicates.rb | UTF-8 | 348 | 3.671875 | 4 | [] | no_license | def remove_duplicates(input_array)
write_index = 0
(1...input_array.size).each do |read_index|
if input_array[read_index] != input_array[write_index]
write_index += 1
input_array[write_index] = input_array[read_index]
end
end
input_array[0...write_index]
end
puts remove_duplicates([2, 3, 5... | true |
21b102576516b5c88fa2c49c0e95e1539219fc68 | Ruby | RuthNjeri/problem_solving | /Alg_design_manual/binary_search_tree.rb | UTF-8 | 2,698 | 4.15625 | 4 | [] | no_license | # Binary tree nodes have a right and left pointer.
# Optional parent pointer and data field
# You can add a third pointer for duplicate items, or a counter.
class Node
attr_accessor :value, :right, :left
def initialize(value)
@value = value # data item
@right = nil # pointer to the right child
@left = ... | true |
5592381124722c9ade55f10a5b970fff82a78588 | Ruby | stmtk1/first_prog | /lexer.rb | UTF-8 | 2,888 | 3 | 3 | [] | no_license | require "./token"
class Lexer
PlusPattern = /^\s*\+/
MinusPattern = /^\s*\-/
MultiplyPattern = /^\s*\*/
DevidePattern = /^\s*\//
LeftParenPattern = /^\s*\(/
RightParenPattern = /^\s*\)/
PowerPattern = /^\s*\^/
ModuloPattern = /^\s*%/
NumberPattern = /^\s*\d+(\.\d+)?/
FunctionPat... | true |
51fa308c02dfdc28f576bd556b0d98350f34ea98 | Ruby | lucascampbell/fantasy_drafter | /lib/tasks/load_players.rake | UTF-8 | 3,294 | 2.609375 | 3 | [] | no_license | require 'csv'
require 'open-uri'
namespace :load_data do
task :cbs_players => :environment do |t, args|
positions = ['RB','WR','QB','TE','K']
path = File.join(Rails.root,"public/projections.csv")
file = File.open(path)
csv = CSV.parse(file)
csv.shift(3)
csv.pop
positions.each do |positio... | true |
52de47c78febdfe081eac5c0d60e18ee112a160c | Ruby | gaoguoxin/Cypress | /app/models/customer.rb | UTF-8 | 896 | 2.765625 | 3 | [] | no_license | class Customer
include Mongoid::Document
include Mongoid::Timestamps
INVALID = 0
VALID = 1
field :username, type: String #供应商姓名
field :address, type: String #收货地址
field :remain, type:Hash #每个客户可能会有赠送的产品,每寄送一批都会有一件赠送的产品,如果用户要这个产品,则该类的值减一,该字段标示可能有多种产品{category_id1:100,category_id2:120}
field :status, ... | true |
c7af0fe3d21100f58e1fedc5a4289ffe119b09e8 | Ruby | barbiecode/my-collect-001-prework-web | /lib/my_collect.rb | UTF-8 | 113 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(array)
array.collect do |name|
name.split(" ").first.upcase
end
end
| true |
0205a919e87e77b74a104eb0f785267af5573745 | Ruby | freerobby/music | /spec/classes/note_spec.rb | UTF-8 | 8,848 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'spec_helper'
include Music
describe Music::Note do
describe "#new" do
it "should allow note strings to initalize notes" do
Note.new('E0').frequency.should == 20.60
Note.new('Bb3').frequency.should == 233.08
end
it "should allow frequencies to initalize notes" do
Note.new(698.... | true |
b2e8c75996d3f6bfddb6403d76fe6df069697ddf | Ruby | ElizabethU/mock-twitter | /spec/models/tweet_spec.rb | UTF-8 | 1,100 | 2.828125 | 3 | [] | no_license | require "spec_helper"
describe Tweet do
# let!(:tweet) { Tweet.create(user: "joetwitter", message: "Wow! Fake twitter is so great!")}
describe "validations" do
it "is valid" do
tweet = Tweet.create(user: "joetwitter", message: "Wow! Fake twitter is so great!")
expect(tweet).to be_valid
end
... | true |
7a845cdab20d64357d74d41820093ff79cee6826 | Ruby | valentinowong/ruby-enumerables-hash-practice-emoticon-translator-lab-nyc-web-071519 | /lib/translator.rb | UTF-8 | 699 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require modules here
def load_library(file_path)
require "yaml"
emoticons = YAML.load_file(file_path)
hash = {}
hash["get_meaning"] = {}
hash["get_emoticon"] = {}
emoticons.each do |k,v|
hash["get_meaning"][emoticons[k][1]] = k
hash["get_emoticon"][emoticons[k][0]] = emoticons[k][1]
end
hash
... | true |
944b726b8ad66c39d36e045855deb3c50ee1b750 | Ruby | joemaidman/student-directory | /exercises/exercise8-10.rb | UTF-8 | 4,896 | 3.828125 | 4 | [] | no_license | # Using gsub as an alternative to chomp
# put students into an array in case the user does not enter anything.
def default_students
students = [
{name: "Dr. Hannibal Lecter",cohort: :november, hobby: :sport, weight: 87, age: 64},
{name: "Darth Vader", cohort: :november, hobby: :reading, weight: 87, age: 53},
{... | true |
51e27e4f48248a2468b2215eef57c3f32593f42b | Ruby | chupa-cabras/loopoolo | /app/models/encounter.rb | UTF-8 | 617 | 2.546875 | 3 | [
"MIT"
] | permissive | class Encounter < ApplicationRecord
has_one :user, as: :target_id
has_one :user, as: :owner_id
validates :target_id, presence: true
validates :owner_id, presence: true
validates :status, presence: true
validates :date, presence: true
#TODO: Change to status
enum status: { open:0, complete:1, cancelled... | true |
53677dab168e51ff00c81403ee33707171286a9a | Ruby | sorashiro/pos-ruby | /pos-v2/model/convert.rb | UTF-8 | 506 | 2.90625 | 3 | [] | no_license | require_relative "cart-item"
class Convert
def load_items(items, inputs)
cart_items = []
items.each do |item|
cart_item = Cart_item.new(item, 0)
inputs.each do |input|
barcode_split = input.split('-')
number = barcode_split[1] || 1
if item.barcode == barcode_split[0] th... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.