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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e3fad9ac0481bbc406268a6db45cbbd10196abb5 | Ruby | rdo9313/aa | /exercises/rspec_exercise_4/lib/part_2.rb | UTF-8 | 352 | 3.71875 | 4 | [] | no_license | def proper_factors(num)
(1...num).select { |n| num % n == 0 }
end
def aliquot_sum(num)
proper_factors(num).reduce(:+)
end
def perfect_number?(num)
aliquot_sum(num) == num
end
def ideal_numbers(n)
array = []
count = 0
i = 1
while count < n
if perfect_number?(i)
count += 1
array << i
... | true |
7592fdefa3ac5b236c8f8defba25865c9a009e5f | Ruby | rpalo/ruby-cs-algorithms | /algorithms/dfs.rb | UTF-8 | 1,802 | 3.703125 | 4 | [
"MIT"
] | permissive | require 'minitest/autorun'
require_relative '../data-structures/undirected_graph'
# Note that DFS is essentially the same as BFS, but uses a stack
# where BFS uses a queue
def depth_first_search(graph, start_node, target)
processed_nodes = []
pending_nodes = [start_node]
# Set up the hash table of nodes to nei... | true |
b5e3254962a0c1d5cb6e30c192632e8aef7b672f | Ruby | princesadie/phase-0 | /week-6/guessing-game/my_solution.rb | UTF-8 | 3,261 | 4.4375 | 4 | [
"MIT"
] | permissive | # Build a simple guessing game
# I worked on this challenge [by myself].
# I spent [1.5] hours on this challenge.
# Pseudocode
=begin
DEFINE 'initialize' method, takes 1 argument, 'answer' (integer)
SET 'answer' instance var equal to 'answer' argument
DEFINE 'guess' method, takes 1 argument, 'guess' (integer)
CRE... | true |
ec07e2dd63432e9e50d0554d795b12c62b804559 | Ruby | stantoncbradley/exercism_ruby | /series/series.rb | UTF-8 | 245 | 3.40625 | 3 | [] | no_license | class Series
def initialize(string)
@string = string
end
def slices(length)
raise ArgumentError.new("length can't be longer than string") if length > @string.length
@string.chars.map(&:to_i).each_cons(length).to_a
end
end
| true |
cd6f146d7698fda1991c9271832ae53bcbb8cc22 | Ruby | mac718/Launch_School | /ruby_basics/methods.rb | UTF-8 | 1,082 | 4.53125 | 5 | [] | no_license | #Greeting Through Methods (Part 1)
def hello
'Hello'
end
def world
"world"
end
puts "#{hello} #{world}"
#Greeting Through Methods (Part 2)
def hello
'Hello'
end
def world
"world"
end
def greet
"#{hello} #{world}"
end
puts greet
#Make and Model
def car(make, model)
puts "#{make} #{model}"
end
car('Toyo... | true |
d176b16955e9b4e39826b6ddb2765df6961dc377 | Ruby | sunny-b/Ruby_Practice | /arithmetic_integer.rb | UTF-8 | 430 | 3.90625 | 4 | [] | no_license | def calculate(num1, num2, op)
puts "Can't perform calculation" if (op == '/' || op == '%') && num2.zero?
"#{num1} #{op} #{num2} = #{num1.send(op, num2)}"
end
def prompt(msg)
puts "=> #{msg}"
end
ops = %w(+ - * / % **)
prompt('Enter the first number:')
first_number = gets.chomp.to_i
prompt('Enter the second nu... | true |
e7fb2724506b2416cd41a2ca987b6f3f627b19ca | Ruby | LucasDerhore/Lexuruby.github.io | /exo_11.rb | UTF-8 | 116 | 3.125 | 3 | [] | no_license | puts "Choisi un nombre :"
nombre = gets.chomp.to_i
compteur = 0
nombre.times { puts "Salut, ca farte ?" }
| true |
8753abcc7b6303335c1ff62017c137bac484e5f4 | Ruby | Bourg/matrix-verify | /matrix.rb | UTF-8 | 2,845 | 2.78125 | 3 | [] | no_license | require 'rdl'
require 'types/core'
type Enumerable, :inject, "(%integer) { (%integer, t) -> %integer } -> %integer"
class Matrix
private_class_method :new
var_type :@rows, 'Array<Array<%integer>>'
var_type :@column_count, '%integer'
type '() -> Array<Array<%integer>>'
def rows
@rows
... | true |
9fbed999e0b0d72d50661055234f73a5405f4a3c | Ruby | GitHubAdmin/MDS3Builder | /app/models/fields/j0400.rb | UTF-8 | 701 | 2.734375 | 3 | [] | no_license | class J0400
attr_reader :title, :options, :name, :field_type, :node
def initialize
@title = "Health Conditions"
@name = "Pain Frequency: Ask resident: 'How much of the time have you experienced pain or hurting over the last 5 days?' (J0400)"
@field_type = DROPDOWN
@node = "J0400"
@options ... | true |
1b4bcf54d623e71d3cd0d650694a867fe41ea374 | Ruby | nihilismus/exercism | /ruby/series/series.rb | UTF-8 | 362 | 3.4375 | 3 | [
"WTFPL"
] | permissive | # frozen_string_literal: true
class String
def enough_length?(size)
size.positive? && size <= length
end
def slices(size)
raise ArgumentError, '' unless enough_length? size
chars.each_cons(size).map(&:join)
end
end
class Series
def initialize(string)
@string = string
end
def slices(le... | true |
e7f1c3e0896aea76a14ba686ea91618cd7c1ee18 | Ruby | maekawatoshiki/lit-x86 | /examples/game.rb | UTF-8 | 395 | 3.96875 | 4 | [
"Unlicense"
] | permissive | def solve min max
mid = min + (max - min) / 2
puts("Is the number smaller than " mid "? or is the " mid " answer? (yes/no/answer)")
ans = gets()
if ans[0] == 'y'
solve(min mid-1)
elsif ans[0] == 'n'
solve(mid+1 max)
elsif ans[0] == 'a'
puts("you choose " mid "!!")
end
end
min = 1
max = 100
puts("Imagine a... | true |
04006774b1c7423f49ee54e428b491215073a775 | Ruby | daneb/assessment | /question2/custom_errors.rb | UTF-8 | 348 | 2.53125 | 3 | [] | no_license | module FlattenIntegerArray
module CustomErrors
class InputValidationError < StandardError
def initialize(message)
super(message)
end
end
def self.raise_validation_exception
notification = "This is not an arbitrarily nested array of integers"
raise InputValidationError, not... | true |
424e32680bca1ea7f9f62716d7ab86f61df1dbf2 | Ruby | zhivou/playground | /algorithms/array_shift_left.rb | UTF-8 | 1,056 | 4.65625 | 5 | [] | no_license | # Shifting whole array on a time left 123 -> 231 -> 312 etc..
# Remember:
# array.shift is take left item and deleting it at the same time it returns its value
# array.push(n) is adding a value at the end of the array and n - what value it should be!
# .join is adding string seportor to the intiger items
#.first return... | true |
31373192fb69a03b51ef5eb4147b3a85ba98589c | Ruby | thomasbrus/predicting-scrabble-game-outcomes | /2-extracting-features/lib/internet_scrabble_club/feature_constructors/first_player_average_score.rb | UTF-8 | 464 | 2.546875 | 3 | [] | no_license | require_relative 'base'
module InternetScrabbleClub
module FeatureConstructors
class FirstPlayerAverageScore < Base
def construct
current_score / number_of_turns.to_f
end
private
def number_of_turns
FeatureConstructors::FirstPlayerNumberOfTurns.new(turns, game).construct... | true |
0969f22b3933817684f2dfc95187fa2e3cbe197c | Ruby | eiriklied/xlsx_parser | /spec/workbook_spec.rb | UTF-8 | 3,054 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe XlsxParser::Workbook do
before :each do
@workbook = XlsxParser::Workbook.new('data/regular_workbook.xlsx')
end
context 'sheets' do
it 'should give the names of the sheets in a workbook' do
expect(@workbook.sheets).to eq ['Sheet number one', 'Number two']
end
... | true |
93b7d01e8bf4a37fce9ed3bdd792974fcf8d7ba6 | Ruby | johnantoni/ruby.json | /solutions/steve/json_parser.rb | UTF-8 | 2,185 | 2.796875 | 3 | [] | no_license | require 'treetop'
File.open("json.treetop", "w") {|f| f.write GRAMMAR }
Treetop.load "json"
parser = JsonParser.new
pp parser.parse(STDIN.read).value if $0 == __FILE__
BEGIN {
GRAMMAR = %q{
grammar Json
rule json
space json_value space { def value; json_value.value; end }
end
rule json_value
stri... | true |
1f16188b95dd97ce2dab72236e914dba9a35b37e | Ruby | Yoshyn/coding_game_spring-challenge-2020 | /tests/path_finder_test.rb | UTF-8 | 13,490 | 2.953125 | 3 | [] | no_license | require "minitest/autorun"
require "pry-byebug"
require_relative "../core_ext/hash"
require_relative "./helper"
require_relative "../path_finder"
require_relative "../scoring_path_finder"
require_relative "../cell"
require 'benchmark'
class TestCell < Cell
def accessible_for?(_ = nil ); data != '#'; end
end
class S... | true |
ce88eb83c944b5ace7922458c6e665e85b69ef60 | Ruby | Azzerty23/THP | /THP-jour12/lib/caesar_cipher.rb | UTF-8 | 742 | 3.5625 | 4 | [] | no_license | def caesar_cipher(message, key=5)
unless message.is_a?(String) && key.is_a?(Integer)
return "The message must be a String and the key an Integer"
end
encoded_message = []
letters = message.split("")
letters.each do |letter|
letter_ascii = letter.downcase.ord
encoded_letter = letter_... | true |
0da0c77cb11ffe6532adb379dbf8c089a5a27f56 | Ruby | ababup1192/Rating_aizu_v2 | /src/view/rating_dir.rb | UTF-8 | 1,032 | 2.578125 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require 'observer'
require 'tk'
module View
class RatingDir
include Observable
def initialize(dialog, rating_dir)
add_observer(rating_dir)
@label = TkLabel.new(dialog){
text '"採点対象ディレクトリ"の場所:'
}
@frame = TkFrame.new(dialog)
@entry = TkEntry.ne... | true |
174789f00e2f7fd4a5bb24f493b7169d5825256f | Ruby | flipstone/codiphi | /engine/examples/functional/parser/formula_spec.rb | UTF-8 | 2,002 | 2.796875 | 3 | [] | no_license | require_relative 'spec_helper.rb'
describe Codiphi::Formula::Parser do
it "parses an integer" do
Codiphi::Formula::Parser.should parse "1"
end
it "parses basic arithmetic operations" do
Codiphi::Formula::Parser.should parse "1 + 2"
Codiphi::Formula::Parser.should parse "1 - 2"
Codiphi::Formula::... | true |
d8673b057e9ae585385086455794f6116243c1be | Ruby | Mycobee/koroibos_api | /spec/requests/api/v1/olympians_request_spec.rb | UTF-8 | 1,866 | 2.640625 | 3 | [] | no_license | require 'rails_helper'
describe "olympians api" do
before :each do
olympian_1_attrs = {
name: "Bob Ross",
sex: "M",
age: 42,
height: 190,
weight: 140,
team: 'USA'
}
sport_1 = Sport.create!(name: 'competitive painting')
@olympian_1 = sport_1.olymp... | true |
9036ccc7cd841a537544eda3f58fb592c66465c5 | Ruby | DenialAdams/mumblecop | /plugins/music_websites.rb | UTF-8 | 2,862 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'open3'
# Feed youtube streams into mpd
class Youtube < Plugin
def initialize
super
@needs_sanitization = true
@commands = %w(youtube yt)
@help_text = 'Play a youtube video - youtube [url] (starting time in seconds)'
@min_args = 1
@quality = :normal
end
def go(source, _command, ar... | true |
473ffa569468fd856c6d6cb01bc733d6e9924e63 | Ruby | tsmall/advent-of-code | /2021/07/ruby/solution.rb | UTF-8 | 1,649 | 3.5625 | 4 | [] | no_license | # Advent of Code 2021
# Day 7: The Treachery of Whales
require 'immutable'
module Day07
module_function
def run
puts "Part 1: #{part_one}"
puts "Part 2: #{part_two}"
end
def part_one(text=nil)
text ||= input.read
positions = parse(text)
most_efficient_dest(positions, method(:naive_fuel_c... | true |
bc5a3848b5d92641db448b6274584377ee1a2589 | Ruby | pa-childs/Udemy_Courses | /learn_to_code-ruby/Section_13/convert_hash_to_array.rb | UTF-8 | 510 | 3.34375 | 3 | [] | no_license | spice_girls = {scary: "Melanie Brown",
sporty: "Menanie Chisholm",
baby: "Emma Bunton",
ginger: "Geri Halliwell",
posh: "Victoria Beckham"}
# Displays each key-value as an array within an array
p spice_girls.to_a
# Can make one non-nested array if desired
p ... | true |
d9ba5b82d9631c29c95566423a716b4e4af25615 | Ruby | sweetyBThareja/rubyCode | /RubymineProjects/ruby_project/accessor.rb | UTF-8 | 729 | 3.921875 | 4 | [] | no_license | class TestClass
def initialize id, name
@id = id
@name = name
end
def id
@id
end
def name
@name
end
def name= s
@name = s
end
end
#Test it works properly
tc = TestClass.new 12, 'Boris'
p tc.id
p tc.name
tc.name = 'Alfie'
p tc.name
#Ruby offers a short cut for getters and setters... | true |
c5c9d7273cbd4a0e5321814cb8e40c711b264ccd | Ruby | wntmddus/Intro-to-Algorithms | /improving_complexity_version_one.rb | UTF-8 | 753 | 2.59375 | 3 | [] | no_license | <<<<<<< HEAD
def poorly_written_ruby(*arrays)
combined_array = []
(0..arrays.length-1).each do |i|
(0..arrays[i].length-1).each do |j|
combined_array << arrays[i][j]
end
end
sorted_array = [combined_array.delete_at(combined_array.length-1)]
for j in (0..combined_array.length-1)
i = 0
... | true |
ba0cf74b337284def25220761f2c8df19db332b6 | Ruby | BenGoldstein88/phase-0-tracks | /something_awesome/song_storage.rb | UTF-8 | 2,962 | 3.90625 | 4 | [] | no_license | # Program that stores songs and related information
# song_name (str), artist_name (str), album_name (str), original_key (str), year (str)
# User should be able to view all songs, an individual song, and input new songs
# require gems
require 'sqlite3'
# create empty SQLite3 database
db = SQLite3::Database.new("son... | true |
d93c87869245d70dffe9821dd87f6502b649ce74 | Ruby | cassiebeisheim/kwk-l1-ruby-2-meal-choice-lab-kwk-students-l1-stl-061818 | /meal_choice.rb | UTF-8 | 1,147 | 4.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Here's an example of a 'snacks' method that returns the meal choice passed in to it and defaults to "cheetos" if nothing is passed in.
def snacks(food="Cheetos")
"Any time, is the right time for #{food}!"
end
# Define breakfast, lunch and dinner methods that return the meal choice passed into them. If nothing is p... | true |
1bb7af320c37c4039291897556e05c9a0ef77e29 | Ruby | jjsanchezrodriguez/game_of_rooms | /spaces.rb | UTF-8 | 1,102 | 3.640625 | 4 | [] | no_license | class Spaces
def initialize(message, objects = [], triggers = [])
@message = message
@objects = objects
@triggers = triggers
@directions = []
end
def add_direction(direction)
@directions.push(direction)
end
def print_message
print "Your are in a #{@message}. "
@objects.each{|object| print "There ... | true |
1fe22d2c426f08a9902ee4cd337248ced5b80f26 | Ruby | littlegustv/redemption | /commands/commands_u.rb | UTF-8 | 552 | 2.859375 | 3 | [] | no_license | require_relative 'command.rb'
class CommandUnlock < Command
def initialize
super(
name: "unlock",
keywords: ["unlock"],
lag: 0.25,
position: :standing
)
end
def attempt( actor, cmd, args, input )
if ( target = actor.tar... | true |
bf88f3d8078bcaed192d81456911c1be1a8373e8 | Ruby | SimonGarber/ar-exercises | /exercises/exercise_1.rb | UTF-8 | 427 | 2.828125 | 3 | [] | no_license | require_relative '../setup'
puts "Exercise 1"
puts "----------"
t = Store.new
t.name = "Burnaby"
t.annual_revenue = 3000000
t.womens_apparel = true
t.mens_apparel = true
t.save
t = Store.new
t.name = "Richmond"
t.annual_revenue = 1260000
t.womens_apparel = true
t.mens_apparel = false
t.save
t = Store.new
t.name = "... | true |
b70c8b8493f833488fb54607300a966c7b949632 | Ruby | annayerofeyeva/noughts-and-crosses | /spec/board_spec.rb | UTF-8 | 1,232 | 2.953125 | 3 | [] | no_license | require './models/board'
describe Board do
let(:board) {Board.new}
let(:cross) {double :choice, :name => "cross"}
it 'should contains nine cells' do
expect(board.grid.length).to eq(9)
end
it 'can access every cell' do
expect(board.find_cell(2)).to eq(nil)
end
it 'can add choiced to a specific cell' do
... | true |
981a023bf0cc978b35c94e0b53bc02f896ddf2bf | Ruby | cogcmd/aws-cfn | /lib/cog_cmd/cfn/definition/create.rb | UTF-8 | 2,493 | 2.578125 | 3 | [] | no_license | require 'cog_cmd/cfn/definition'
require 'cfn/command'
require 'cfn/branch_option'
require 'cfn/definition'
module CogCmd::Cfn::Definition
class Create < Cfn::Command
include Cfn::BranchOption
DEFINITION_NAME_FORMAT = /\A[\w-]*\z/
TEMPLATE_NAME_FORMAT = /\A[-\w\/]*\z/
def run_command
require_... | true |
c72dcdf134af4485b0aee7b73ef4a75516501f3d | Ruby | francesmx/learn_to_program | /ch11-reading-and-writing/safer_picture_downloading.rb | UTF-8 | 1,051 | 3.421875 | 3 | [] | no_license | pic_names = Dir["../*.{JPG,jpg}"] # Search in the parent directory
puts "What would you like to call this batch?"
batch_name = gets.chomp
puts
print "Downloading #{pic_names.length} files: "
pic_number = 1
pic_names.each do |name|
print "."
new_name = if pic_number < 10
"#{batch_name}0#{pic_number}.jpg"
... | true |
e3cdcf6f28b421dafbbde0085c79d1565f3471a9 | Ruby | rb512/algorithms | /project_euler/problem6.rb | UTF-8 | 110 | 2.875 | 3 | [] | no_license | def sum_difference(n)
sum = (n*(n+1)/2)
sum_of_squares = n*(n+1)*(2*n +1)/6
(sum*sum)-sum_of_squares
end | true |
b3c716d182492e0d1a4d69f930eaa071988b9fb1 | Ruby | ozzman84/funny_2107 | /lib/open_mic.rb | UTF-8 | 462 | 3.265625 | 3 | [] | no_license | class OpenMic
attr_reader :location,
:date,
:performers
def initialize(hash)
@location = hash[:location]
@date = hash[:date]
@performers = []
end
def welcome(user)
@performers << user
end
def repeated_jokes?
all_jokes = []
@performers.each { |pe... | true |
5e6192e9fad77254f8b57c30e0749df785c8827b | Ruby | Nejuf/Poker | /lib/Poker.rb | UTF-8 | 2,794 | 3.5625 | 4 | [] | no_license | require_relative "Player"
require_relative "Deck"
require_relative "Hand"
class Poker
BETTING_COMMANDS = %w(fold raise call withdraw)
attr_accessor :players, :deck, :pot
def initialize
@players = [Player.new("Sleepy", 100), Player.new("Snooky", 100), Player.new("Darwin", 100), Player.new("Snoop Lion", 100... | true |
26a3c55971e6020e7609cce9b919483ac0428693 | Ruby | kevinpark07/ruby-project-guidelines-nyc01-seng-ft-080320 | /app/models/get_character.rb | UTF-8 | 292 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'net/http'
require 'open-uri'
require 'json'
class GetCharacter
URL = "https://www.potterapi.com/v1/characters?key=$2a$10$9cotrn8hm2vhEzS8mtY.dO3NJ9uobAe9MuERDSy9iR1K10b8kqvvy"
def get_characters
uri = URI.parse(URL)
response = Net::HTTP.get_response(uri)
JSON.parse(respo... | true |
956c81a5768f46a980fcc7caa8ae58926d4fce78 | Ruby | j1wilmot/Challenges | /ProgramThis/3_circle/circle.rb | UTF-8 | 211 | 3.078125 | 3 | [] | no_license | radius = Integer(ARGV[0])
if radius.nil? || radius < 1
abort("Need to provide a radius greater than 0")
end
CHAR = "#"
0.upto(radius) do |i|
puts " " * (radius - i) + CHAR
end
radius.downto(0) do |i|
end
| true |
f5c6d992c597a004133c8b39bca039242d8c4784 | Ruby | panozzaj/conf | /common/bin/cp_with_mkdir_p | UTF-8 | 497 | 2.96875 | 3 | [] | no_license | #!/usr/bin/ruby
require 'fileutils'
src, target=ARGV
if target =~ /\/$/ # create the directory if it doesn't exist
unless File.directory?(target)
puts "Creating directory #{target}"
FileUtils.mkdir_p target
end
else # assuming we want to copy the file to that name
dirname = File.dirname(targ... | true |
3417e58efd3fab24d6484651c89ed66ae4910a0b | Ruby | wudip/need-not-to-speed | /lib/model/game/map/objects/stop_sign.rb | UTF-8 | 4,545 | 3.3125 | 3 | [
"MIT"
] | permissive | require 'model/game/crashable'
module NeedNotToSpeed
module Game
# Stop sign - object in map. Player has to stop at least
# square root of "#{SQR_STOPPING_AREA_LENGTH}" from it.
class StopSign
# Length of area before the stop sign where car has to stop (squared to
# make computation easier)
... | true |
0185ba392d3e2dbd7ec6344522d9af4c663410f6 | Ruby | ngsmrk/euler | /problem_5.rb | UTF-8 | 368 | 3.4375 | 3 | [] | no_license | # naive slow solution!!
start_time = Time.now
i = 0
upper_number = 20
def divisible(number, range)
range.each do | num |
return false unless number % num == 0
end
end
while true
i += upper_number
puts i
break if divisible(i, (1..upper_number))
end
elapsed_time = Time.now - start_time
puts "Elapse... | true |
b0931d5cee0839b59f3bddedee5da260aa5dc08e | Ruby | AkiraBrand/sorting_cards | /lib/Deck.rb | UTF-8 | 844 | 3.359375 | 3 | [] | no_license | require 'Pry'
require_relative './Card'
require_relative './Guess'
class Deck
attr_reader :cards,
:value,
:suit,
:deck
def initialize(cards)
@cards = cards
@empty_array = []
end
def count
@cards.count
end
def sort
values = {"4 of Hearts" => 1,
"... | true |
415022404eef7ac4c870de340f8838e4c0f76208 | Ruby | tamu222i/ruby01 | /tech-book/5/5-9.rb | UTF-8 | 132 | 3.453125 | 3 | [] | no_license | # 未定義メソッドの呼び出し
class Bar
def method_missing(name, *args)
puts name
end
end
b = Bar.new
b.hoge
hoge
| true |
10154a12a8e1ac3d2b8e52dec99f0af4aa7cf6a7 | Ruby | kayeon/sea-c21-ruby | /lib/class7/exercise4.rb | UTF-8 | 1,701 | 4.6875 | 5 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# 5 points
#
# Copy the previous OrangeTree class and replace the following method:
#
# OrangeTree#initialize(fruit = 50)
#
# Sets it's `@fruit` instance variable to the `fruit` parameter, which
# defaults to 50.
#
# orange_tree = OrangeTree.new
# orange_tree.fruit #=> 50
#
# ... | true |
fbc603d9ad2d8606b7f07854f180d509f05cffc9 | Ruby | ekosz/spacedice | /spec/cup_spec.rb | UTF-8 | 1,072 | 3.328125 | 3 | [] | no_license | require 'spec_helper'
require_relative '../lib/cup'
class MockDie; end
describe Cup do
it "can give a random dice inside it" do
die = MockDie.new
cup = Cup.new([die])
cup.take(1).should == [die]
end
it "can give all the dice inside it" do
die1 = MockDie.new
die2 = MockDie.new
die3 = Moc... | true |
22b0731052c444da015f487050b2b646ac7513a2 | Ruby | blogmitnik/CheckMe | /lib/tasks/import_data.rake | UTF-8 | 2,519 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'csv'
require 'fileutils'
desc "This task is for importing data from csv file into database"
task :import_data, [:filename] => :environment do
puts "Fetching csv files from local folder..."
imported_files = []
imported_main_files = []
imported_mini_files = []
duplicated_files = []
filtered_csvs_from_t... | true |
0dff3e93ebc6720d0d25563953250cc51db8fa55 | Ruby | techtronics/monster_manual | /app/models/creature.rb | UTF-8 | 430 | 2.796875 | 3 | [] | no_license | require "dice"
class Creature < ActiveRecord::Base
belongs_to :monster
def bloodied?
hit_points <= monster.bloodied
end
def take_damage!(amount)
self.hit_points -= amount
self.hit_points = 0 if hit_points < 0
end
def incapacitated?
hit_points == 0
end
def get_defaults_from_monster
return unle... | true |
cb4300332815c812edcfe4cb8a2a5d9fb1e154a2 | Ruby | geekgrl1965/Wyncode-homework | /classes2.rb | UTF-8 | 1,273 | 3.921875 | 4 | [] | no_license | class Table
@@next_table_id = 1
attr_reader :id
def initialize #applied to every instance of the class
@id = @@next_table_id #instance variable using class variable
@@next_table_id +=1
end
def change_next_id(next_id)
@@next_table_id = next_id
end
def self.next_table_id
@@next... | true |
b472255a7b1cb495db45e7f96805b3ea9617c67f | Ruby | douglaskurotaki/rails-tdd | /exemplo_ruby_rspec/spec/matchers/change/chage_spec.rb | UTF-8 | 485 | 2.765625 | 3 | [] | no_license | require 'contador'
# Verifica se houve mudanca no valor
describe 'Matcher change' do
# Verifica se houve mudanca qualuqer
it { expect{ Contador.incrementa }.to change { Contador.qtd } }
# Verifica se a mudanca foi alterada para 1 valor a mais
it { expect{ Contador.incrementa }.to change { Contador.qtd }.by(1... | true |
fbade188cedc6c6034689186239e592d9735c343 | Ruby | DrFriendless/rmud | /wizards/lib/bodyutil.rb | UTF-8 | 2,694 | 3.296875 | 3 | [] | no_license | # FIXME: items can't claim two spots of the same type, e.g. you can't have an item which is two rings.
module Wearing
def initialize_wearing
@wear_slots = {'necklace' => [nil], 'hat' => [nil], 'ring' => [nil, nil], 'amulet' => [nil],
'righthand' => [nil], 'lefthand' => [nil], 'shoes' => [nil]}
... | true |
cda6a220b727135f068ea1bdc7cafeed874627bb | Ruby | mythographer/fuel_app | /test/models/fuel_type_test.rb | UTF-8 | 1,946 | 2.53125 | 3 | [] | no_license | require 'test_helper'
class FuelTypeTest < ActiveSupport::TestCase
def setup
@petrol = fuel_types :petrol
end
test 'responds to name_en, name_ua, abbr_name' do
%i(name_en name_ua abbr_name).each do |attr|
assert_respond_to @petrol, attr
end
end
test 'should be valid' do
assert @petrol... | true |
e94bacf72ec69cd38e449f19bcfd8d5a01d3a64d | Ruby | saganawski/Project-Euler | /sum_squares.rb | UTF-8 | 693 | 4.03125 | 4 | [
"MIT"
] | permissive |
# The sum of the squares of the first ten natural numbers is,
# 12 + 22 + ... + 102 = 385
# The square of the sum of the first ten natural numbers is,
# (1 + 2 + ... + 10)2 = 552 = 3025
# Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 26... | true |
ad204e5b0c2c91bfe39ab1a39407aa5253110cf0 | Ruby | crishoj/dep_feat | /lib/conll/corpus.rb | UTF-8 | 1,890 | 3.0625 | 3 | [] | no_license |
module Conll
class Corpus
attr_reader :sentences, :filename
def self.parse(file)
Corpus.new(file) do |corpus|
File.new(file).each("\n\n") do |part|
lines = part.split(/\n/)
corpus << Conll::Sentence.parse(lines)
end
end
end
def <<(sentence)
sent... | true |
66b8fc1fc4b2933a01aa52fb7d5e3f22d43073cc | Ruby | kaineer/phonelib | /test/dummy/test/unit/phone_test.rb | UTF-8 | 992 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class PhoneTest < ActiveSupport::TestCase
test "saves with valid phone" do
phone = Phone.new(number: '972541234567')
assert phone.save
assert phone.errors.empty?
end
test "can't save with invalid phone" do
phone = Phone.new(number: 'wrong')
assert !phone.save
asse... | true |
9f3c525c7f0ef21f1a9ef6a9c842269f0bcfe5a7 | Ruby | austinoso/ruby-oo-object-relationships-collaborating-objects-lab-sfo-web-012720 | /lib/artist.rb | UTF-8 | 705 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist
attr_accessor :name
@@all = []
def initialize(name)
@name = name
@songs = []
@@all << self
end
def songs
Song.all.filter { |song| song.artist == self }
end
def add_song(song)
song.artist_name = self.name
end
def self.find_or_c... | true |
79c9b6f118ae011ba8c4abf6c64d21927fae1672 | Ruby | CouteauFourchette/rubychess | /display.rb | UTF-8 | 1,125 | 3.328125 | 3 | [] | no_license | require 'colorize'
require_relative 'cursor'
require_relative 'history'
require 'byebug'
class Display
def initialize(board = Board.create_new_board, cursor)
@board = board
@cursor = cursor
@history = History.instance
end
def render
row_notation = [8,7,6,5,4,3,2,1]
column_notation = ['a','b'... | true |
8ba647c08d04ecd55e722d644787fbd91072a759 | Ruby | SureshDamodaran/MyStuff | /Exercise_6_To_10/ex7_WithAddedComments.rb | UTF-8 | 737 | 4.4375 | 4 | [] | no_license | puts "Mary had a little lamb."
# In the below line snow is a string not a variable.
puts "Its fleece was white as #{'snow'}."
puts "And everywhere that Mary went."
puts "." * 10 # What'd that do? It prints dot 10 times.
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u... | true |
ab0033df55f5363d748d9885a6dd8d4262c1713b | Ruby | conceptric/stock-data-recorder | /spec/stock-data-recorder/stock_data_recorder_spec.rb | UTF-8 | 3,391 | 2.65625 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'csv'
describe Stock::Data::Recorder do
let(:tickers) { %w(BP.L GSK.L) }
use_vcr_cassette "yahoo-api-query", :record => :new_episodes
describe ".new" do
it "with an array of ticker symbols returns a new instance" do
... | true |
1f8ea3e4acd01db280a7f189e450cc5d6b002d83 | Ruby | aramoe/exercism | /ruby/resistor-color-duo/resistor_color_duo.rb | UTF-8 | 226 | 2.875 | 3 | [] | no_license | class ResistorColorDuo
COLORS = %w( black brown red orange yellow green blue violet grey white )
def self.value(names) =
names.take(2) # duo
.map{|name| COLORS.index(name).to_s }
.join('')
.to_i
end
| true |
1dd73a6cf8cdeeba9bf8fedf41a54df1dda6f147 | Ruby | ac1714/mx_record | /lib/mx_record.rb | UTF-8 | 1,514 | 2.828125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'resolv'
module MXRecord
# Obtain the mail exchange record for a particular domain.
#
# Returns an array of Resolv::DNS::Resource::IN::MX records e.g. for Google:
#
# [ #<Resolv::DNS::Resource::IN::MX:0x007faaac870da8 @preference=50, @exchange=#<Resolv::DNS::Name: alt4.aspmx.l.google.com.>, @ttl=347... | true |
18dcdb035a98775c2708be4a23604af4a546537d | Ruby | kargo-k/prime-ruby-seattle-web-060319 | /prime.rb | UTF-8 | 241 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Add code here!
def prime?(num)
if num < 4 && num > 1
return true
elsif num <= 1
return false
else
arr = Array(2...num)
arr.each do |i|
if i ** (num-1) % num == 1
return true
else
return false
end
end
end
end | true |
2c952e731b72c5149150068bd3f46c812d1eaad3 | Ruby | eliasjpr/poker_time | /lib/card.rb | UTF-8 | 494 | 3.53125 | 4 | [] | no_license | class Card
# The order of rankings and suits is VERY IMPORTANT (low to high) for ranking
RANKINGS = %w(2 3 4 5 6 7 8 9 T J Q K A).freeze
SUITS = %w(C D H S).freeze
def self.build_deck
RANKINGS.compact.inject([]) do |deck, rank|
deck << SUITS.map { |s| "#{rank}#{s}" }
end.flatten
end
attr_rea... | true |
9eb568f5213caaad37f448a49594029c63e3d46c | Ruby | buty4649/atcoder | /abc307/c/main.rb | UTF-8 | 1,118 | 3.3125 | 3 | [] | no_license | # frozen_string_literal: true
def parse(h)
# 左上から0,0とし、最初と最後の0を削除しておく
result = h.times.map { gets.chomp.reverse }
# 左に詰めつつ2進数にする
shift = result.map { |r| r.index('#') || h }.min
result.map { |r| r[shift..].gsub('#', '1').gsub('.', '0').to_i(2) }
.drop_while(&:zero?) # 縦列の最初の0を削除
.reverse.dro... | true |
c2c6d26738fa4ab8c5c3cdb57075ee4f4d873055 | Ruby | muskarab/GenerasiGigih | /Modul_4/Session_2/integer_array_incrementer.rb | UTF-8 | 260 | 3.171875 | 3 | [] | no_license | class IntegerArrayIncrementer
def increment(input)
if input == [9]
return [1, 0]
if input.first == 9
[input.first + 1]
end
else
return [input.first + 1]
end
end
end | true |
059db4b38e51ec8c3bfd601b49a115bd9cedaf84 | Ruby | Arithmetics/auction | /test/models/draft_test.rb | UTF-8 | 1,959 | 2.59375 | 3 | [] | no_license | require 'test_helper'
class DraftTest < ActiveSupport::TestCase
setup do
@draft2018 = drafts(:six)
@draft2016 = drafts(:four)
@player1 = players(:one)
@player2 = players(:two)
@user1 = users(:one)
@bid1 = bids(:one)
@bid2 = bids(:two)
@bid3 = bids(:three)
@user1 = users(:one)
... | true |
396f6cabde2228340c518a704cf1161e3a5ee2e4 | Ruby | unboxed/gdata | /lib/gdata/auth/authsub.rb | UTF-8 | 5,847 | 2.546875 | 3 | [
"Apache-2.0"
] | permissive | # Copyright (C) 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | true |
a1c90abdaefee627ddba6b12f5a374c489b3ecda | Ruby | Hyan18/boris-bikes-2 | /lib/docking_station.rb | UTF-8 | 602 | 3.203125 | 3 | [] | no_license | class DockingStation
docking_station = DockingStation.new
attr_reader :bikes
DEFAULT_CAPACITY = 20
def initialize(capacity = DEFAULT_CAPACITY)
@capacity = capacity
@bikes = []
end
def release_bike
fail "no bikes available" if empty?
fail "no working bikes available" if working_bikes.... | true |
aa909542b0544b3ad8d43e79a60851bfe9411a2d | Ruby | Directrix777/yield-and-return-values-onl01-seng-ft-070620 | /lib/practicing_returns.rb | UTF-8 | 361 | 3.96875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def hello(array)
i = 0
collection = []
while i < array.length
collection << yield(array[i])
i += 1
end
collection
end
#Collecting the return values of the puts statement would just give you nil,
#but I'll code your broken method, since that's what the lab says to do.
hello(["Tim", "Tom... | true |
833baf959a08644b3b09c47e83c3fe7a2edf2e6d | Ruby | uvlad7/summer-2019 | /211/1/gem_scorer.rb | UTF-8 | 1,017 | 3 | 3 | [] | no_license | require 'yaml'
require 'table_print'
require_relative './gem_info.rb'
class GemScorer
def call(options)
list = load_gemlist(options[:file])
gem_names = filter_by_name(list, options[:name])
gems_array = get_gems_info(gem_names)
gems_array.sort_by!(&:popularity).reverse!
gems_array = take_top(gems_... | true |
3faeb8cb9e6ea3578b4765e6908dfbc92a5633e8 | Ruby | stevenproctor/lsrc_bbd_training | /lib/restaurant.rb | UTF-8 | 550 | 3.515625 | 4 | [] | no_license | class Restaurant
MAXPRICE = 5
MINPRICE = 0
attr_accessor :ratings, :price, :location
def initialize
@ratings = []
@price = 0
end
def score
return 0 if ratings.empty?
return ratings.inject(:+) / ratings.count
end
def add_rating(new_rating)
ratings << new_rating
end
def set_l... | true |
87a82d545f6c6614753817b06b899eb4818384b7 | Ruby | CerrilloMedia/mememe | /app/helpers/posts_helper.rb | UTF-8 | 1,111 | 2.53125 | 3 | [] | no_license | module PostsHelper
def randomDeletionConfirmationMessage
prepost = "Post Deleted,"
confirmations = [
"#{prepost} your secret is safe with me.",
"#{prepost} I guess you really didn't want anyone to know about this thing that happened you know when",
"#{prepost} perhaps next time we should st... | true |
9c4d4a9477a8d43a8e3db12ad27ed8fa3e3c49ba | Ruby | cpsexton/ruby-enumerables-hash-practice-emoticon-translator-lab-denver-web-82619 | /lib/translator.rb | UTF-8 | 928 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require modules here
require "yaml"
require "pry"
def load_library(file_path)
emoticon_lib = YAML.load_file(file_path)
new_hash = {}
emoticon_lib.each do |emotion, symbol_array|
new_hash["get_meaning"] ||= {}
new_hash["get_emoticon"] ||= {}
new_hash["get_meaning"][symbol_array.last] ||= emotion
... | true |
fdbe79554a36ac18226517e0c9b93321ee933bd4 | Ruby | albertbahia/wdi_june_2014 | /w03/d02/peter_pak/homework/homework_in_class/pokemon/poke_battle.rb | UTF-8 | 340 | 2.875 | 3 | [] | no_license | require 'pry'
require_relative 'lib/pokemon.rb'
require_relative 'lib/trainer.rb'
def fight_night(fighter1, fighter2)
# map?
end
trainer1 = Trainer.order(random()).limit(1)
trainer2 = Trainer.order(random()).limit(1)
trainer1.choose_pokemon(Pokemon.get_pokemon)
trainer2.choose_pokemon(Pokemon.get_pokemon)
fight_... | true |
737f205981e8367f6a40e3052fd39c449b971cb7 | Ruby | gitter-badger/spectro | /lib/spectro/compiler.rb | UTF-8 | 1,884 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'spectro'
require 'spectro/spec/parser'
require 'yaml/store'
module Spectro
# Spectro::Compiler is in charge of scan the projects and parse its files,
# updating the Spectroi's index and dumping information about the missing
# implementations (specs without an associated lambda)
class Compiler
in... | true |
c070ef4915a48b36981578eec5e290f070d17b67 | Ruby | Suyog242/mc-lease-specials | /lib/extracters/subaru/extractor.rb | UTF-8 | 6,567 | 2.671875 | 3 | [] | no_license | require_relative "../../../lib/extracters/base/base_extractor"
require_relative "../../../lib/utils/http_get"
require "pry"
require "awesome_print"
require 'logging'
require 'logger'
require 'nokogiri'
require_relative "op_format.rb"
class Extractor < BaseExtractor
def initialize(make, zip)
super(make, zip)
... | true |
f92627c6b20203e3876523abfe50b944732aafbb | Ruby | jacobswartzentruber/project_euler | /problem_30.rb | UTF-8 | 939 | 4.34375 | 4 | [] | no_license | #Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
#1634 = 14 + 64 + 34 + 44
#8208 = 84 + 24 + 04 + 84
#9474 = 94 + 44 + 74 + 44
#As 1 = 14 is not a sum it is not included.
#The sum of these numbers is 1634 + 8208 + 9474 = 19316.
#Find the sum of all the nu... | true |
00159143282e744fc32686b5c87060e29a42d6f6 | Ruby | hby910830/Full-Stack | /Ruby面向对象/include.rb | UTF-8 | 396 | 3.21875 | 3 | [] | no_license | module Module1
def my_method
'M1#my_method()'
end
end
class Class1
include Module1 # 相当于 C1 < M1,但是不能继承一个模块,只能继承一个类
end
class Class2 < Class1; end
# [Class2, Class1, Module1, Object, Kernel, BasicObject]
p Class2.ancestors # 出现 Kernel 是因为 Object include 了 Kernel,比如 print 就定义在 Kernel 里
# 接下来看 prepend.rb | true |
00e9f15a9b005ad67172cde33c7b8fdb04352496 | Ruby | strayllama/music_library__SQL_LAB_14thFeb | /models/album.rb | UTF-8 | 1,452 | 3.265625 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
class Album
attr_accessor :genre, :title
attr_reader :id, :artist_id
def initialize(options)
@genre = options['genre']
@title = options['title']
@id = options['id'].to_i if options['id']
@artist_id = options['artist_id'].to_i
end
def save()
sql ... | true |
1619c78bbee50ab7207d4148038378388ecbbc89 | Ruby | Engoh4/rubyWork | /loop_iterators/conditional_loop.rb | UTF-8 | 62 | 2.8125 | 3 | [] | no_license | i=0
loop do
puts i
if i==10
break
end
i+=1
end | true |
79348d125176e0bc27f5f8344a95240e5f220f62 | Ruby | kamnnm/todobot | /lib/todobot/commands.rb | UTF-8 | 1,704 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'todobot/services/commands/help_command_service'
require 'todobot/services/commands/start_command_service'
require 'todobot/services/tasks/create_task_service'
require 'todobot/services/lists/create_list_service'
require 'todobot/services/lists/show_list_service'
require 'todobot/services/lists/show_lists_servi... | true |
35b5609645d1a01cc2f138ce64ae5cd15aa10778 | Ruby | GL2-G4/SlitherLink | /Noyau/GestionTechniques/Techniques/2Cases/TroisAvecTroisDiag.rb | UTF-8 | 4,724 | 2.734375 | 3 | [] | no_license | ##
# File: TroisAvecTroisDiag.rb
# Project: 2Cases
# File Created: Wednesday, 18th March 2020 1:48:16 pm
# Author: <CPietJa>Galbrun T.
# -----
# Last Modified: Thursday, 26th March 2020 4:05:01 pm
# Modified By: <CPietJa>Galbrun T.
#
path = File.expand_path(File.dirname(__FILE__))
require path + "/../../Technique"
req... | true |
f55ff561e87bf7a8030909845016f610eda80ecf | Ruby | ScottyP90/Homework_week_1_day_5 | /pet_shop.rb | UTF-8 | 1,489 | 3.375 | 3 | [] | no_license | def pet_shop_name (name)
return name [:name]
end
def total_cash (sum)
return sum [:admin][:total_cash]
end
def add_or_remove_cash (shop, cash)
return shop [:admin][:total_cash] += cash
end
def pets_sold (sold)
return sold [:admin][:pets_sold]
end
def increase_pets_sold (sold, amount)
return sold [:admin][... | true |
fe0c98f0e3be658a54cb0f5678dc5a4dd1c4e97d | Ruby | MarceloWis/Algoritmos-e-Estruturas-de-Dados | /Ruby/ExponenciacaoRecursiva.rb | UTF-8 | 198 | 3.65625 | 4 | [
"MIT"
] | permissive |
def exponenciacao(base, expoente)
if expoente == 0
return 1
else
return base * exponenciacao(base, expoente-1)
end
end
puts exponenciacao(5, 2)
puts exponenciacao(5, 5) | true |
0c000908a5eb358ede73d8001e86acd876d2003d | Ruby | simonista/ruby_synth | /bin/freq | UTF-8 | 713 | 3.25 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'ruby_synth'
require 'io/console'
puts "starting"
stream = RubySynth::AudioStream.new
s1 = RubySynth::Sine.new
stream.load(s1)
FREQ_INC = 1.05946309 # ~ 12th root of two
counter = 0
start = Time.now.to_i
STDIN.raw do |i|
loop do
begin
c = i.read_nonblock(1)
s1.frequen... | true |
a4c8fd4d906bbe450e977374fb7bd90e8e043982 | Ruby | Lukatastic/ics_bc_w18 | /week4/recursion_practice/factorial.rb | UTF-8 | 316 | 3.96875 | 4 | [] | no_license | # For this exercise we will not provide any skeleton code (other than the method declaration).
# See if you can figure out how to write the method!
def factorial(n)
if n == 0 || n == 1
return 1
else
return n*factorial(n-1)
end
end
#puts(factorial(3)) # expected: 6
#puts(factorial(10)) # expected: 3628800
| true |
c0a0ff8afbf0d7298362d0659bf36b158c6c7edc | Ruby | mflm30/moodle-tcc | /app/services/sync_tcc.rb | UTF-8 | 3,473 | 2.671875 | 3 | [
"MIT"
] | permissive | # app/services/sync_tcc.rb
class SyncTcc
def initialize(context)
@tcc_definition = context
@errors = {}
@remote_service = MoodleAPI::MoodleUser.new
end
def call
students = get_students
unless students.nil?
students.with_progress "Sincronizando #{students.size} TCCs para #{@tcc_defini... | true |
a8a81d7217252db09879cef3048916d9ee6e7804 | Ruby | paulfioravanti/three_little_pigs | /test/lib/chapters/chapter_14_wolf_attacks_straw_house_test.rb | UTF-8 | 1,151 | 2.890625 | 3 | [
"CC-BY-4.0",
"MIT"
] | permissive | # frozen_string_literal: true
require "test_helper"
module ThreeLittlePigs
module Chapters
class Chapter14WolfAttacksStrawHouseTest < Minitest::Test
attr_reader :story, :wolf, :first_pig, :second_pig
def setup
suppress_output do
@story = Story.until_chapter(Chapter14WolfAttacksStr... | true |
b146c39647833607c715b3926e381a2c3e0baf42 | Ruby | vasileios-samarinas/week02_sports_team_student_classes_homework | /sports_team.rb | UTF-8 | 632 | 3.5625 | 4 | [] | no_license | class Team
attr_accessor :team,:players,:coach,:points
def initialize(team,players,coach,points)
@team=team
@players=players
@coach=coach
@points=points
end
def team
return @team
end
def players
return @players
end
def coach
return @coach
end
def add_new_player(footbal... | true |
29a311981118096226389a7ab04591a5f47a6cd2 | Ruby | prashu47/Euler_project | /largest_prime_factor.rb | UTF-8 | 756 | 3.84375 | 4 | [] | no_license | # frozen_string_literal: true
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?
#--------------------------------------------------------------------------------#
def largest_prime_factor(num)
primefactor = 2
while primefactor < num
if num % prim... | true |
007b7cd91cc6c7ac391479fc21e3af5ec2d6cd6d | Ruby | navi-mann/Programming-Fundamentals-Collections-and-Iteration | /excercise.rb | UTF-8 | 3,753 | 2.734375 | 3 | [] | no_license | fav_colours = ["pink","purple","yellow","orange"]
age = [29,27,36,28]
coin_flip = ["tails","tails","tails","heads","heads"]
performing_artists = ["Beyonce", "Kanye", "Adele"]
fav_colours2 = [:pink,:purple,:yellow,:orange]
dictonary = {cunt:"a woman's genitals.",fleek: "To shit on ones education and pull shit out of th... | true |
6f9dece0e512d5e542e091a0e827e86c9c166a07 | Ruby | MaleehaBhuiyan/Rails-Practice-Code-Challenge-Travelatr-nyc01-seng-ft-060120 | /app/models/blogger.rb | UTF-8 | 558 | 2.78125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Blogger < ApplicationRecord
has_many :posts
has_many :destinations, through: :posts
validates :name, :presence => true
validates :name, :uniqueness => true
validates :age, numericality: { greater_than: 0 }
validates :bio, :length => { :minimum => 31}
# total likes
def total_lik... | true |
0ec8606162caa8803bbe245ec9502e3825d05739 | Ruby | Marissab13/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 683 | 4.0625 | 4 | [] | no_license |
puts "Would you like to encrypt or decrypt a password today?"
crypt = gets.chomp
puts "Enter a password"
password = gets.chomp
def encryption(str)
index = 0
while index < str.length
str[index] = str[index].next!
index += 1
return str
end
end
def decryption(str)
index = 0
decode = "&"
reference = ... | true |
f5ce8d66daade2d9c38f4aed4ea3a821a2b0b733 | Ruby | BedfordWest/megdumarra | /systems/physics/collisions/collisions.rb | UTF-8 | 231 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | module Collisions
def check_collisions(world)
world.bodies.combination(2).each { |body1, body2|
if (body1.collides body2)
world.add_contact(body1, body2)
end
}
end
end | true |
c1c927ca299e3185e3082c5d0486bb6ba9b1a112 | Ruby | MJWangler/RB101-109 | /RB 101 Small Programs/lesson_3/practice_medium_1/one.rb | UTF-8 | 204 | 3.03125 | 3 | [] | no_license | #Write a one-line program that creates "The Flintstones Rock!" output 10 times, with each subsequence indented 1 space to the right
10.times { |number| puts (" " * number)} + "The Flintstones Rock!" } | true |
61d0f49dff222880a3d059b2e769606b5d8aa20f | Ruby | anmolk18/ruby-oo-relationships-practice-gym-membership-exercise-yale-web-yss-052520 | /lib/gym.rb | UTF-8 | 466 | 3.15625 | 3 | [] | no_license | class Gym
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
def memberships
Membership.all.select{|membership| membership.gym == self}
end
def lifters
memberships.map{|membership| membership.lifter}.uniq
end
def ... | true |
cbc3f4d6240c51b8729788fa213c9eb1c43246b4 | Ruby | agraniero/crud-with-validations-lab-online-web-ft-112618 | /app/models/song.rb | UTF-8 | 1,008 | 2.859375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ActiveRecord::Base
validates :title, presence: true
validates :artist_name, presence: true
validate :invalid_release_year_if_released_true
validate :release_year_included?
validate :invalid_if_artist_releases_song_same_year
def invalid_release_year_if_released_true
if relea... | true |
16e2a7b97864f2aa7fa41708eea03403b25a7262 | Ruby | Big-Theta/EulerProblems | /cameron/p082/p82.rb | UTF-8 | 726 | 2.953125 | 3 | [] | no_license | require "faceted.rb"
def problem82
m, m_dim = gimme_matrix
prev_col = []
(0..m_dim[1]).each do |y|
prev_col[y] = m[[0, y]]
end
(1..m_dim[0]).each do |x|
curr_col = []
(0..m_dim[1]).each do |y|
curr_col.push(m[[x, y]])
end
prev_col = min_vertical(prev_col, curr_col)
end
prev_col.... | true |
cb00e7a7b628d7793e0b7bf60e86f86430a3d238 | Ruby | jss530/my-collect-v-000 | /lib/my_collect.rb | UTF-8 | 213 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_collect(collection)
if collection.length > 0
i = 0
any_collection = []
while i < collection.length
any_collection << yield(collection[i])
i = i + 1
end
any_collection
end
end
| true |
3cdc29553b953c7fde533a5bf3426fad91c5adfc | Ruby | varindersingh/wiziq-instructure-canvas-plugin | /lib/wiziq/crypto_helper.rb | UTF-8 | 329 | 2.703125 | 3 | [
"MIT"
] | permissive | module Wiziq
class CryptoHelper
attr_reader :signature_base
def initialize
@signature_base = ""
end
def add_param(key,value)
@signature_base += "&" if !@signature_base.empty?
@signature_base << key << "=" << value.to_s if !key.nil? && !value.nil?
@signature_base
end
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.