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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4762cb03bdb46308d150842ce55bf8fe7183dd0e | Ruby | iamquartey/ruby-challenges | /lesson_11_write_methods.rb | UTF-8 | 77 | 2.53125 | 3 | [] | no_license | # Skillcrush 104 - Write Methods
# Adnan Quartey
def add_two
puts 2 + 2
end
add_two | true |
feb4c617ec49dccce358159a5ff8f3e34363e508 | Ruby | rkclark/sinatra-challenge | /lib/app.rb | UTF-8 | 467 | 2.578125 | 3 | [] | no_license | require 'sinatra'
set :session_secret, 'super secret'
get '/' do
'Hello!'
end
get '/secret' do
'Secret stuff'
end
get '/otherstuff' do
'Other stuff'
end
get '/random-cat' do
@name = ['bob', 'bill','donald','obama'].sample
erb(:index)
end
get '/named-cat' do
p params
p request.body
p request.quer... | true |
aa35ba8ae35138ed21be228fdea7c5aedd97f495 | Ruby | corespring/mongo-db-utils | /integration-test-env/helper.rb | UTF-8 | 1,215 | 2.625 | 3 | [
"MIT"
] | permissive | require 'yaml'
require 'fileutils'
require 'mongo'
class MongoEnvMaker
attr_reader :pids
def initialize(root_folder)
@root_folder = root_folder
@pids = []
end
def spawn(port, rs_name = nil)
`mkdir -p #{@root_folder}/logs/#{port}`
out_log = "#{@root_folder}/logs/#{port}/out.log"
err_log ... | true |
fa5e9848370e07871ab28afc40a8e21def4016a7 | Ruby | alxsanborn/tic-tac-toe-rb-q-000 | /lib/tic_tac_toe.rb | UTF-8 | 2,915 | 4.1875 | 4 | [] | no_license | WIN_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]]
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " ... | true |
a184920632e82a9263efaeaf3ff47f1cf5781475 | Ruby | victorwu3/grails-mvc | /grailedorm/base.rb | UTF-8 | 2,429 | 2.71875 | 3 | [
"MIT"
] | permissive | require_relative 'db_connection'
require 'active_support/inflector'
require_relative '02_searchable'
module GrailedORM
class Base
extend GrailedORM::Searchable
extend GrailedORM::Associatable
def self.columns
@columns ||= DBConnection.execute2(<<-SQL).first.map(&:to_sym)
SELECT
*
... | true |
9dbf29537bd9260c8d765697ddca8c713a919a1f | Ruby | jeffersonsc/app_estoque2.0 | /app/models/produto.rb | UTF-8 | 1,122 | 2.703125 | 3 | [] | no_license | class Produto < ActiveRecord::Base
#def self.import(file)
## atribui as variáveis informação do arquivo
#nome = file.original_filename
#diretorio = "public/data"
#formato = file.content_type
#date = Time.now
## Uni as informções do diretorio com o nome do arquivo
#path = File.join(diretorio , date.strf... | true |
b6b4a011cfc3c944b6a84a67010123b1b758c13e | Ruby | hkulekci/treehouse-ruby-notes | /05-Arrays/sorting-and-comparison.rb | UTF-8 | 306 | 3.53125 | 4 | [] | no_license | array = [5, 2, 1, 3, 3, 10]
puts "Default Array"
puts array.inspect
puts "Sorted Array"
puts array.sort.inspect
puts array.sort{|a, b| a <=> b}.inspect
puts "Reverse Sorting"
puts array.sort{|a, b| b <=> a}.inspect
puts array.sort.reverse.inspect
puts "Remove multiple elements"
puts array.uniq.inspect | true |
8d151f541a37e0f630e8f93f0d1c5a1401099701 | Ruby | DarthCharles/sofe-finalchallenge | /ruby-api/lib/models/flights.rb | UTF-8 | 442 | 2.71875 | 3 | [] | no_license | require "date"
module FarandulaSample
class Flight
attr_accessor :departureAirport, :departureDate, :arrivalAirport, :arrivalDate, :segments
def initialize (args = {})
@departureAirport = args[:departure_airport]
@departureDate = args[:departure_date]
@arrivalAirport = args[:arri... | true |
c737b88883a0ace1587dd5a379f0d706526eaad4 | Ruby | mattzuzolo/practice-oo-associations | /venue.rb | UTF-8 | 552 | 3.21875 | 3 | [] | no_license | require 'pry'
# require_relative './console.rb'
class Venue
attr_accessor :title, :city
ALL = []
def initialize(title, city)
@title = title
@city = city
ALL << self
end
def self.all
ALL
end
def concerts
# lists all the concerts that have ever been performed in that venue
Con... | true |
c42557981981761477dea576cf0c707a9590bee2 | Ruby | dankim93/chess | /rook.rb | UTF-8 | 211 | 2.6875 | 3 | [] | no_license | require_relative 'piece'
require_relative 'sliding_pieces'
class Rook < Piece
include SlidingPieces
def initialize(*args)
super(*args)
end
def move_dir
[:up, :down, :left, :right]
end
end
| true |
237a115c014edf64c6b737998488de0c6f896057 | Ruby | phutang/sales_taxes | /app/helpers/price_helper.rb | UTF-8 | 467 | 2.953125 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2014 Phu Tang
# All rights are reserved.
module PriceHelper
def tax_round(number)
parts = (number * 10).to_s.split('.')
left_part = parts[0].to_f
right_part = parts.count > 1 ? parts[1].to_i : 0
if right_part > 0
fraction = "0.#{right_part}".to_f
if fraction < 0.5
... | true |
5b778b4178ef08549011c617b47a269432f3f637 | Ruby | Marcellofabbri/Oystercard-challenge | /spec/Oystercard_spec.rb | UTF-8 | 1,223 | 3.03125 | 3 | [] | no_license | require 'Oystercard'
describe Oystercard do
let(:station) { double(:station) }
let(:station2) { double(:station2) }
describe '#balance' do
it "has a default balance of zero" do
expect(subject.balance).to eq 0
end
end
describe '#top_up' do
it { is_expected.to respond_to(:top_up).with(1).... | true |
2390e1d1809e90fa43fe6f8e5ffa830a5e6e804f | Ruby | linseyo/phase-0-tracks | /ruby/problem_solving_methods.rb | UTF-8 | 1,444 | 4.46875 | 4 | [] | no_license | #takes in an integer then searches for that integer
number_searcher = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
number_hash = Hash[number_searcher.map.with_index.to_a]
p number_hash[4]
# # p number_searcher.length
# #take the length --> to search for number
# #search for number --> specific index
# def search_for
# number_... | true |
5a1cfe470536dc6aaacf2f48fe6c6357af32428b | Ruby | maclarensg/rubyrepo | /quiz/3way_min_sum_part/run2.rb | UTF-8 | 369 | 3.171875 | 3 | [] | no_license | #!/usr/bin/env ruby
require "prime"
class Integer
def proper_divisors
return [] if self == 1
primes = prime_division.flat_map{|prime, freq| [prime] * freq}
(1...primes.size).each_with_object([1]) do |n, res|
p "#{n}, #{res}"
primes.combination(n).map{|combi| res << combi.inject(:*)}
... | true |
34a035f1ac529a926fc351e4d4efef2b5df83bfd | Ruby | bibikhadiza/looping-while-until-001-prework-web | /lib/while.rb | UTF-8 | 134 | 2.890625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_while
levitation_force = 6
while levitation_force < 10 do
puts "Wingardium Leviosa"
levitation_force +=1
end
end
puts using_while
| true |
8021a562d108e8f381299878e91736a6c4695e97 | Ruby | jasylwong/code-reviews | /code-review-3/Ruby/lib/spell_checker.rb | UTF-8 | 310 | 3.75 | 4 | [] | no_license | def spell_checker(input)
correct_words = ["cat", "music", "dog", "the", "nice", "try", "good", "guess"]
words = input.split(" ")
output = []
words.each do |word|
if correct_words.include?(word.downcase)
output << word
else
output << "~#{word}~"
end
end
output.join(" ")
end | true |
b3105935cd8437bb5c74e2165525bba78a9ca238 | Ruby | mattcl/weechat_notifier | /lib/weechat_notifier/xmobar.rb | UTF-8 | 1,170 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'securerandom'
require 'weechat_notifier/config'
require 'weechat_notifier/logging'
module WeechatNotifier
class Xmobar
include Logging
def self.max_len
@max_len ||= Config.data['xmobar']['max_len'].to_i
end
def self.filename
'xmobar-chats'
end
def self.path
@pat... | true |
df91b022413f0d36b04c348c7da66b762f8a5641 | Ruby | rpluu/ics_bc_s18 | /week2/ch07/leap_year_counter.rb | UTF-8 | 459 | 4.125 | 4 | [] | no_license | puts 'What is your starting year?'
s_year = gets.chomp.to_i
puts 'What is your ending year?'
e_year = gets.chomp.to_i
if e_year < s_year
puts 'Ending year must be greater than starting year.'
elsif e_year > s_year
puts 'The leap years between ' + s_year.to_s + ' and ' + e_year.to_s + ' are:'
end
while e_year >= ... | true |
f9e367c137b2c8e3b9fa70410b2d1ce531ab632f | Ruby | mc-chinju/like-slack | /config/initializers/super_monkies/string.rb | UTF-8 | 347 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "mail"
class String
def with_4bytes?
/[\u{10000}-\u{10ffff}]/
end
def valid_email?
m = Mail::Address.new self
return false unless m.domain && m.address == self
return false if m.address.match?(/\.\.|__|^\W|\W@/)
return false unless m.domain.split(".").s... | true |
5f2b60b1ae6316fba0bd2a5f3ad4e9ec61930edb | Ruby | RKoopman/sql-crowdfunding-lab-web-0616 | /lib/sql_queries.rb | UTF-8 | 1,702 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your sql queries in this file in the appropriate method like the example below:
#
# def select_category_from_projects
# "SELECT category FROM projects;"
# end
# Make sure each ruby method returns a string containing a valid SQL statement.
def selects_the_titles_of_all_projects_and_their_pledge_amounts
"SELECT... | true |
5930f1815a95c139c4af10f1389b3add633f4e33 | Ruby | tongji98/006957 | /sugoroku/sugoroku.rb | UTF-8 | 811 | 3.359375 | 3 | [
"BSD-3-Clause"
] | permissive | #!/usr/bin/ruby -s
# -*- coding: utf-8 -*-
# -*- Ruby -*-
def usage
name = File::basename $0
print <<EOU
#{name}: 쌍육 주사위 게임
(예)
#{name} 10 → 10 회 시행
(옵션 예)
-t=2,3,7 또는 -trap=2,3,7 → 2, 3, 7 번째 말에 함정을 판다
-s=777 또는 -seed=777 → 난수의 시드를 지정
-help 또는 -h → 이 메시지를 표시
EOU
end
#################... | true |
a4ce939eafcbc450c386380cf121fc0c758b59b3 | Ruby | Kisuke-CZE/playlist_transfer | /lib/playlist_transfer/extensions.rb | UTF-8 | 967 | 3.328125 | 3 | [] | no_license | #Some enhancements to standard classes created to fit my needs
require 'active_support/inflector'
class Pathname
# Adds new method to Pathname, which removes accented characters from Pathname. Then removes spaces and any special characters (they are replaced by _). This method returns another Pathname.
def no_spe... | true |
c0dfcbdf40dd9233efb477d16a837319d5a9fa98 | Ruby | caterspot/thermal_printer | /lib/thermal_printer/formatter.rb | UTF-8 | 863 | 2.71875 | 3 | [
"MIT"
] | permissive | module ThermalPrinter
class Formatter
attr_reader :content, :type, :align, :bold, :xformat, :width, :height
def self.format(content, options = {})
new(content, options).format
end
def initialize(content, options = {})
@content = content
@type = options[:type]
@align = options... | true |
51496d282baccb2bdcdc2367700e011c5fe22ef3 | Ruby | vmanamino/cmd_line_ruby | /fibo.rb | UTF-8 | 502 | 3.390625 | 3 | [] | no_license | def fibo
nth = ARGV.shift
count = nth
# counter = 0
counting = 0
current = 0
collection = []
while counting < count.to_i
if counting < 2
collection.push(current)
current += 1
else
previous = collection[counting - 2]
current = collection[counting - 1]
current = current... | true |
ae2e61246a961f303c00ec25fd7ace5c67645aa3 | Ruby | BlueMeadow/L3 | /S6/PROJET/Hanjie-master/Grille/Cellule.rb | UTF-8 | 3,750 | 3.578125 | 4 | [] | no_license | # Cette classe représente une case de la grille de picross
# chaque cellule est définie par son état (blanche/noicie ou barrée)
# @see Constants.rb
# Il est impossible de colorier en noir une case barrée comme il est impossible de barrer une case noircie
# L'état d'une cellule change (ou pas) selon le clic qu'on fait d... | true |
85f393ee178c1dfbd3c0c5d639c6aa1af172faa6 | Ruby | cmp3715/Ruby_Fundamentals1 | /exercise4.rb | UTF-8 | 76 | 3.203125 | 3 | [] | no_license |
value = (true && false) || (false&& true) || !(false && false)
puts value
| true |
b7ec04fc2c136d2a3020d0f3fb7cd89a34a409dc | Ruby | brettshollenberger/Cal-Poly-CS-365 | /install/lib/mysql_table.rb | UTF-8 | 487 | 2.890625 | 3 | [] | no_license | require "mysql2"
class MysqlTable
attr_accessor :database_name, :table_name
def initialize(database_name, table_name)
@database_name = database_name
@table_name = table_name
end
def count
client.query("select count(*) from #{table_name}").first.values.first
end
def delete_all
client.q... | true |
3626bc7bf3cfb84127deac8d80b7006992be82a5 | Ruby | djsteve33/ruby-object-attributes-lab-onl01-seng-pt-041320 | /lib/dog.rb | UTF-8 | 285 | 3.6875 | 4 | [] | no_license | class Dog
def name=(name)
@name = name
end
def name
@name
end
def breed=(breed)
@breed = breed
end
def breed
@breed
end
end
benji = Dog.new
benji.name = "Benji"
puts benji.name
snoopy = Dog.new
snoopy.breed = "Beagle"
puts snoopy.breed | true |
38ea6f863987b5c4d8a7cfa39bbf84d4563dc124 | Ruby | emi9361/Ruby01 | /lesson7.rb | UTF-8 | 162 | 3.328125 | 3 | [] | no_license |
puts "2つの値を入力してください"
a = gets.to_i
b = gets.to_i
puts "計算結果を抽出します"
puts "a*b=#{a*b}"
puts "計算を終了します" | true |
8930c86c94f285130b8eb4cbce14219948ab27ff | Ruby | matilhaestudio/rails_matching | /spec/rails_matching_spec.rb | UTF-8 | 1,818 | 2.53125 | 3 | [
"MIT"
] | permissive | require "spec_helper"
RSpec.describe RailsMatching do
context "Setup"
it "has a version number" do
expect(RailsMatching::VERSION).not_to be nil
end
it "creates a user to run tests" do
user = create(:user)
expect(user).to be_instance_of(User)
end
it "creates a list of users to run tests" do
... | true |
cdb8fce4a4c52fd9679ac473e5a6511e84a0568a | Ruby | josearmandojacq/oding_project | /ruby excercises/caesar_encrypt.rb | UTF-8 | 958 | 3.6875 | 4 | [] | no_license | # frozen_string_literal: true
require "byebug"
class CaesarEncrypt
def self.call(text, factor)
new(text, factor).encrypt
end
def encrypt
encrypted_text = ''
text.each_char do |letter|
if letter? letter
encrypted_text += encrypt_upper_case(letter) if upper_case?(letter)
encryp... | true |
588bcdbd010e592d4f3596820e239d13f7efd7d1 | Ruby | akoinesjr/phase_0_unit_2 | /week_5/2_die/my_solution.rb | UTF-8 | 1,334 | 4.71875 | 5 | [] | no_license | # U2.W5: Die Class 2: Arbitrary Symbols
# I worked on this challenge [by myself, with: ].
# 2. Pseudocode
=begin
DEFINE class Die
DEF initialize function that takes argument labels
UNLESS there is at least one side
raise an error message
END
declare an instance variable called labels
END
DEF sides f... | true |
9fc1cba30c7b4a9b16a854231bb43d95c4c54f7f | Ruby | lillers1122/grocery-store | /specs/online_order_spec.rb | UTF-8 | 4,840 | 2.734375 | 3 | [] | no_license | require 'pry'
require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/skip_dsl'
require 'awesome_print'
# TODO: uncomment the next line once you start wave 3
require_relative '../lib/online_order'
# You may also need to require other classes here
# Because an OnlineOrder is a kind of Order, and we'... | true |
63b9d8bff4bc582fa52cf42e55703023bc530359 | Ruby | DKassai/array-CRUD-lab-ruby-apply-000 | /lib/array_crud.rb | UTF-8 | 627 | 3.765625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
array = []
end
def create_an_array
array = [1,2,3,4]
end
def add_element_to_end_of_array(array, element)
array = array<<(element)
end
def add_element_to_start_of_array(array, element)
array=array.unshift(element)
end
def remove_element_from_end_of_array(array)
array = array.pop()... | true |
1dd730b5cf1375e46d20ad2264342965363dfd34 | Ruby | Em01/practice | /time.rb | UTF-8 | 608 | 4.375 | 4 | [] | no_license | #the Time class
#represents moments in Time
#you can add or subtract numbers to or from times to get new times.
#adding 1.5 to a time makes a new time one and a half second later
time = Time.new # The moment I generated this web page.
time2 = time + 60 # One minute later.
puts time
puts time2
=>
Tue Apr 14 16:... | true |
bd451b1efd64d64e6692204a16eb0518df060938 | Ruby | pwnall/rockbands_bot | /rocker_shows.rb | UTF-8 | 2,332 | 2.875 | 3 | [
"MIT"
] | permissive | # :nodoc: Rocker extensions for shows.
class Rocker
# The shows that the player can perform.
def shows
refresh_shows! if @shows.nil?
@shows
end
# Refreshes the cached list of shows that the player can perform.
def refresh_shows!
@shows = _shows
end
# Drives the player to perform the given ... | true |
cca3c3d1c023e624ec76a22a199d73bb75509957 | Ruby | BaltimorePublicArtCommons/baltimore_public_art_commons | /app/models/importers/csv/model_creator.rb | UTF-8 | 1,226 | 2.6875 | 3 | [] | no_license | module Importers
class Csv::ModelCreator
def self.create_model_from_row(model_name: nil, row: nil, unique_attrs: nil)
self.new.create_model_from_row(model_name, row, unique_attrs)
end
def create_model_from_row(model_name, row, unique_attrs)
attrs = find_model_attrs_in_row(model_name, row)
... | true |
b2fd2b89015d544cc61edff40df9f9ca26a38833 | Ruby | molybdenum-99/mediawiktory | /lib/mediawiktory/wikipedia/actions/liststudents.rb | UTF-8 | 1,879 | 2.984375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module MediaWiktory::Wikipedia
module Actions
# Get the usernames and other information for students enrolled in one or more courses.
#
# Usage:
#
# ```ruby
# api.liststudents.courseids(value).perform # returns string with raw output
# # or
# api.liststud... | true |
e0e271870ecff7c454e479418b838639b21fa08d | Ruby | rhardih/aoc | /2020/19p1.rb | UTF-8 | 3,749 | 3.828125 | 4 | [] | no_license | =begin
--- Day 19: Monster Messages ---
You land in an airport surrounded by dense forest. As you walk to your
high-speed train, the Elves at the Mythical Information Bureau contact you
again. They think their satellite has collected an image of a sea monster!
Unfortunately, the connection to the satellite is having ... | true |
0b257c9ec6dd3b3e414d0bb8b55a98a0923031d1 | Ruby | ryanttb/internet_monitor | /lib/retrievers/asn_parser.rb | UTF-8 | 556 | 2.8125 | 3 | [] | no_license | class ASNParser
require 'csv'
def data(options = {})
filename = options[:filename]
column = options[:column]
data = []
csv = CSV.open(filename, { :headers => true })
csv.each do |row|
country = Country.find_by_iso_code(row['Code'])
next unless cou... | true |
1f7aff23e7b3f39e548d12f5ea88912fa31c3841 | Ruby | ragesoss/WikiWalkBot | /wiki_walk_bot.rb | UTF-8 | 1,260 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'wikipedia_twitterbot'
Article.connect_to_database 'wikiwalkbot'
class WikiWalkBot
def initialize(dry_run: false)
@dry_run = dry_run
end
def start_walking
Article.import_at_random min_views: 1000
article = Article.all.sample
tweet = Tweet.new(first_tweet article).result
sleep 5
... | true |
bb13c980e8af2595dd16bc5faf28343932a4416b | Ruby | BaronLip/MyTTF_React-Redux-App | /myttf-api/app/controllers/api/v1/matches_controller.rb | UTF-8 | 5,485 | 2.65625 | 3 | [] | no_license | class Api::V1::MatchesController < ApplicationController
def index
matches = Match.where(player_id: params[:player_id])
render json: matches, status: 200
end
def show
match = Match.find(params[:id])
games = match.games
render json: {
match: matc... | true |
e24836e7505a648ac1dd436a73a73060ac18731f | Ruby | rafeDraper/spende_app | /vendor/bundle/ruby/2.7.0/gems/pundit-2.1.0/lib/pundit.rb | UTF-8 | 12,263 | 2.609375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "pundit/version"
require "pundit/policy_finder"
require "active_support/concern"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/module/introspection"
require "active_support/dependencies/autoload... | true |
c7f433a0b593e3046f3fdbc123c0499007ecc011 | Ruby | ortuagustin/RepairTracking | /app/models/repair.rb | UTF-8 | 1,279 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | class Repair < ApplicationRecord
has_many :revisions, dependent: :delete_all
belongs_to :customer
belongs_to :artifact
after_create :generate_repair_code, :set_pending_state, :set_cost
validates :estimated_days, numericality: { only_integer: true }
def estimated_date
self.created_at + self.estimated... | true |
f48b9de49fae24e7d0cbbe0287c15da8841c82f3 | Ruby | thailehuy/hunt_party_game | /app/models/battle_round.rb | UTF-8 | 2,549 | 3.0625 | 3 | [] | no_license | class BattleRound < ApplicationRecord
belongs_to :hunt
has_many :battle_actions
delegate :party, :monster, to: :hunt, prefix: false
def calculate_outcome
calculate_monster_attack
calculate_party_attack
end
def calculate_monster_attack
targetted_character = determine_monster_target
calcula... | true |
05b113b1a5e23496ccc196225ee7479e7cbda5fd | Ruby | domitian/aureso | /app/models/concerns/pricing_policy.rb | UTF-8 | 1,873 | 2.71875 | 3 | [] | no_license | module PricingPolicy
extend ActiveSupport::Concern
require 'open-uri'
require 'nokogiri'
require 'rss'
def calculate_total_price
PriceCalculator.new(self.model.organisation.pricing_policy,self.base_price).get_price
end
class PriceCalculator
def initialize policy,base_price... | true |
5c9c7f8001fad34c072932685096e36e7cfed850 | Ruby | pazcuturi/Trabajo-OnBoarding | /Apprenticeship - Basic/Ruby/Ruby Ejercicio/git.rb | UTF-8 | 739 | 3.109375 | 3 | [] | no_license | puts "Ingrese un nombre del archivo que quiere subir como un Gist de GitHub... "
puts "No se olvide de finalizar el archivo con '.txt'"
userfile= gets.chomp
filename = userfile
puts "Añade una descripción..."
description = gets.chomp
puts"Quieres que tu repositorio sea publico?"
state = gets.chomp.capitalize
if stat... | true |
f4edc3f4630b3b1932e3ecc03be9f5808d227511 | Ruby | xtreme-jesse-malone/grocer | /lib/grocer/pusher.rb | UTF-8 | 388 | 2.796875 | 3 | [
"MIT"
] | permissive | module Grocer
class Pusher
def initialize(connection)
@connection = connection
end
def push(notification)
@connection.write(notification.to_bytes)
end
# close pusher connection
# NOTE: connection will wait [timout] seconds
# for any possible error response from apple.
def... | true |
4f9075ac9227c9d1ad1e10e4e3df4347d6a7f642 | Ruby | Se7enB2st/Algorithm | /square_of_two.rb | UTF-8 | 221 | 3.5625 | 4 | [] | no_license | # Create a method which check if number is a square of 2
def square_of_two(number)
return false if number == 0
while(number % 2 == 0)
number = number / 2
end
return false if number > 1
true
end
| true |
67085aadef974a05d4a8ed6ff7ac97f7d6109169 | Ruby | tiborh/ruby | /oo/singleton_class3.rb | UTF-8 | 407 | 3.578125 | 4 | [] | no_license | #!/usr/bin/env ruby
# source:
# https://www.devalot.com/articles/2008/09/ruby-singleton
foobar = [] # and instance of Array
puts "No singleton_methods: #{foobar.singleton_methods}"
# creation of a singleton class
class << foobar
def foo
"Hello World!"
end
end
puts "after the 'class << f... | true |
98cfc87c29c3b5025fee6360b7a60c845185b58f | Ruby | meghaniankov/boris-bikes | /lib/docking_station.rb | UTF-8 | 649 | 3.25 | 3 | [] | no_license | require_relative 'bike'
class DockingStation
DEFAULT_CAPACITY = 20
def initialize(capacity=DEFAULT_CAPACITY)
@bike_rack = []
@capacity = capacity
end
attr_reader :bike_rack, :capacity
def release_bike
if @bike_rack.empty?
raise('No bikes in bike rack')
else
@bike_rack.each { |b... | true |
a382463df6573579a93f2eaf5bb7e36b0e15552b | Ruby | rleon1608/Pico_Placa_ruby | /pico_placa.rb | ISO-8859-1 | 2,807 | 3.921875 | 4 | [] | no_license | require 'date'
require 'time'
#Programa realizado por:Ronald Leon
# Simulador de Pico y Placa
# Datos de entrada: placa, Fecha y Hora
# Salida: indicar si el carro puede estar en circulacion o no
# define la clase placa
class Placa
# mtodo inicializar clase
def initialize(arg_placa)
# atributos ... | true |
852637bc023c74621a02928409cb7c8b04bf9611 | Ruby | MutmutBlop/THP_S2_J5 | /lib/mkdiruby.rb | UTF-8 | 1,042 | 2.71875 | 3 | [] | no_license | def everything
#------ CREATE THE FOLDER
abort("Entre le nom du fichier (sans espaces) après ta commande :)") if ARGV.empty? || ARGV.length > 1
folder_name = ARGV.first
Dir.mkdir(folder_name)
#------
#------ INITIALIZE THE REPOSITORY IN THE FOLDER
Dir.chdir ("#{folder_name}")
system("git init")
#---... | true |
a20c9e529b0878323d1666cc04ab11188573d7c7 | Ruby | bmedici/bmc-daemon-lib | /lib/bmc-daemon-lib/mq_endpoint.rb | UTF-8 | 1,109 | 2.515625 | 3 | [
"MIT"
] | permissive | module BmcDaemonLib
class MqEndpoint
include LoggerHelper
attr_accessor :logger
def initialize channel, *args
# Init
@channel = channel
log_info "MqEndpoint on channel [#{@channel.id}]"
end
protected
def log_message msg_way, msg_topic, msg_key, msg_body = [], msg_attrs = {}... | true |
04c0401261ffd93cdeabfab7ea820f960f80d7d5 | Ruby | larrykooper/follow-info | /app/controllers/tag_controller.rb | UTF-8 | 1,074 | 2.671875 | 3 | [] | no_license | class TagController < ApplicationController
def edit
if request.method == "GET"
@tags = Tag.order("name")
end
if request.method == "POST" # It posts to itself
# Get list of all tags
tags = Tag.all
# Set up two hashes of all tags
published_hash = Hash.new
ids_hash = Ha... | true |
7498e389c90ebc474cd61672601ce4a875665b61 | Ruby | nrepasy/ruby-oo-relationships-practice-boating-school-exercise | /app/models/boatingtest.rb | UTF-8 | 395 | 2.90625 | 3 | [] | no_license |
class BoatingTest
attr_accessor :test_name , :test_status , :instructor
attr_reader :student
def initialize(student,test_name,test_status,instructor)
@student = student
@test_name = ("")
@test_status = ("")
@name = instructor
@@all << self
end
def name
... | true |
c780cb5beb6ecc82dcfc02583ba03ce17d6f96e3 | Ruby | ardes/scam | /lib/ardes/scammable.rb | UTF-8 | 2,263 | 2.671875 | 3 | [
"MIT"
] | permissive | module Ardes
# extended into ActiveRecord, adds macros to associate any model with scam(s)
module Scammable
# the default scam class for all ActiveRecords (can be overridden on a per class basis)
mattr_accessor :scam_class_name
self.scam_class_name = 'Scam'
def has_scam(*names)
extend Class... | true |
22836248c13d9a03209c28a5f92e1f18ba5ba434 | Ruby | jasonmolenda/hockey-sched | /original-version/hockey-calendar-creator.cgi | UTF-8 | 32,952 | 3.171875 | 3 | [
"BSD-3-Clause"
] | permissive | #! /usr/bin/ruby
require 'open-uri'
require 'date'
require 'time'
require 'etc'
require 'cgi'
@DEBUG = false
def initialize_matrix(mat, dim)
1.upto(dim) do |i|
mat[i] = Array.new
1.upto(dim) do |j|
if i == j
mat[i][j] = 1
else
mat[i][j] = 0
end
end
end
end
def matri... | true |
43e99b79265b7953357fafe76084cfc588f45b47 | Ruby | bryanarboledaa/ruby-projects | /ruby_activity/lesson_2_encapsulation_abstraction_pholymorphism/polymorphism_inheritance.rb | UTF-8 | 678 | 3.5 | 4 | [] | no_license | class Polymorphism
def initialize(name, position, department)
@full_name = name
@position = position
@department = department
end
def introduce
puts "Hi Polymorphism, I'm #{@full_name}, #{@position} from #{@department} department."
end
end
class Poly < Polymorphism
def introduce
puts "Hi... | true |
bac6ed79ff57811649d71982d7700ba63c59f2d3 | Ruby | scorphus/bookbinder | /lib/bookbinder/commands/run_publish_ci.rb | UTF-8 | 1,048 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | require_relative 'bind'
require_relative 'build_and_push_tarball'
require_relative 'chain'
require_relative 'naming'
require_relative 'push_from_local'
module Bookbinder
module Commands
class RunPublishCI
include Commands::Naming
include Commands::Chain
def usage
[command_name,
... | true |
b092e616dee2604374d2fb4a7d746a308f4f357b | Ruby | chrischavarro/ironhack-pt | /week0/not_ironhack/codeacademy_frequency_count.rb | UTF-8 | 603 | 4.03125 | 4 | [] | no_license | puts "Entery your sentence:"
text = gets.chomp
words = text.split
frequencies = Hash.new(0) #Creates a new hash named frequencies for the sake of counting instances
words.each do |word| #Makes it so that every word entered adds to the frequency by 1
frequencies[word] += 1
end
frequencies = frequencies.sort_by do |wo... | true |
18e6d160bac8e07bfaaa7a3111b500240346429c | Ruby | Shane0018/ruby_fundamentals1 | /exercise7.rb | UTF-8 | 193 | 3.015625 | 3 | [] | no_license | counter = 1
while counter < 4
puts "counter currently at #{counter}"
counter += 1
end
counter = 3
until counter == 0
puts "counter currently at #{counter}"
counter -=1
end
| true |
efe25382e487e5415a4d32b8df1312abd80b2830 | Ruby | tommykail11/hangman | /hangman.rb | UTF-8 | 2,402 | 4.28125 | 4 | [] | no_license | class Hangman
@tries_left = 8
@blank = ""
@game_lost = false
@game_won = false
def self.blank
@blank
end
def self.blank=(blank)
@blank = blank
end
def self.tries_left=(tries_left)
@tries_left = tries_left
end
def self.tries_left
@tries_left
end
def self.game_lost
@game... | true |
1fcefff26d81fb2c01e02b7238fafd0b93a69f5f | Ruby | DaveTD/dashing-paddles | /lib/gameset.rb | UTF-8 | 967 | 3.09375 | 3 | [] | no_license | require 'celluloid/autostart'
class GameSet
include Celluloid
attr_accessor :player1, :player2, :active_game, :id
def initialize(p1, p2, server, id)
@id = id
@server = server
@active_game = nil
@player1 = p1
@player2 = p2
@player1.client.send("g:1")
@player2.client.send("g:2")
@towin = 3
checkMa... | true |
6af88bfef31cf80223523d82ec4d53d0248fb6e3 | Ruby | JoshCNelson/data_structures_and_algorithms | /Ruby Challenges/3.2/luhn.rb | UTF-8 | 852 | 3.703125 | 4 | [] | no_license | class Luhn
attr_reader :number
def initialize(number)
@number = number
end
def checksum
addends.reduce(:+)
end
def addends
result = []
processed_number = number.to_s.reverse.chars.map(&:to_i)
processed_number.each_with_index do |num, index|
if index.odd?
resul... | true |
cfed2ed6d9d0323807776aa8b69cf45be45b5f2c | Ruby | o19s/quepid | /test/models/solr_arg_parser_test.rb | UTF-8 | 977 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
require 'test_helper'
require 'solr_arg_parser'
class SolrArgParserTest < ActiveSupport::TestCase
test 'it creates a new solr Args' do
sa = SolrArgParser.parse('a string')
assert sa.is_a? Hash
end
test 'split lines and clean whitespace' do
sa = SolrArgParser.parse("
... | true |
b3e53f59764b809e965a178bef05b424a6e549b1 | Ruby | jose-luis-ramos-olivares/mayor_de_4_numeros | /mayor_de_4.rb | UTF-8 | 238 | 3.1875 | 3 | [] | no_license | a = ARGV[0].to_i
b = ARGV[1].to_i
c = ARGV[2].to_i
d = ARGV[3].to_i
if (a >= b) && (a >= c) && (a >= d)
puts a
elsif (b >= a) && (b >= c) && (b >= d)
puts b
elsif (c >= a) && (c >= b) && (c >= d)
puts c
else
puts d
end
| true |
6a7db382ed693a83238318f21d3ee5ac80d60526 | Ruby | btagliani/murmuring_spider | /lib/murmuring_spider/operation.rb | UTF-8 | 1,946 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'dm-core'
require 'dm-validations'
require 'twitter'
#
# Operation: represents request to Twitter
#
module MurmuringSpider
class Operation
include DataMapper::Resource
property :id, Serial
property :type, String
property :target, String
property :opts, Object
validates_uniqueness_of... | true |
086b8a9dc3cf138f807ddc5ba4cb5fa5dd81244b | Ruby | fritzek/steam | /lib/steam/session.rb | UTF-8 | 1,002 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'locator'
# Conceptually a session is something different than a browser. E.g. a (test-)
# session can be started (setting up test data etc.) and stopped (cleaning
# stuff up etc.). Webrat and Capybara don't separate these concepts. So let's
# keep them separate though from the beginning even though we don't i... | true |
7eefab444446269d876d737e12afa0f78c173e9e | Ruby | scarlett7x/w18_icsbc | /week3/ch09/new_roman_numerals.rb | UTF-8 | 1,058 | 3.609375 | 4 | [] | no_license | def romanize_new number
number = gets.chomp.to_i
while (number < 1 || number > 3000)
puts "Please enter a value between 0 and 3001"
end
while (number > 0 && number < 3001)
mod_M = number % 1000
mod_D = number % 500
mod_C = number % 100
mod_L = number % 50
mod_X = number % 10
mod_V = number % 5
num_M = ... | true |
9c343d2caf892cf6d3daf1ab83a01a82062e6921 | Ruby | dentarg/gists | /gists/rbu/rbu | UTF-8 | 531 | 3.109375 | 3 | [] | no_license | #!/usr/bin/env ruby
if STDIN.tty?
if ARGV.empty? || ARGV.first =~ /-h|--help/
abort <<~USAGE
Usage:
#{File.basename(__FILE__)} [code point] - get Unicode character
echo ... | #{File.basename(__FILE__)} - get Unicode code point
Examples:
$ #{File.basename(__FILE__)} 26... | true |
8946a2f05b69ac95970cbb84df68e5984f0a2da6 | Ruby | giladbu/badgeville | /lib/badgeville/helpers.rb | UTF-8 | 332 | 2.515625 | 3 | [] | no_license | module Badgeville
module Helpers
def property_params(object_name, params)
params.inject({}) do |new_params, entry|
k, v = entry
new_params["#{object_name.to_s}[#{k.to_s}]"] = v
new_params
end
end
def ensure_array(items)
items.is_a?(Array) ? items : [items]
en... | true |
cca7813d1e42cb5e83efbf023963322a448b337c | Ruby | LadyMozzarella/flash.me | /spec/decks_controller_spec.rb | UTF-8 | 2,084 | 2.546875 | 3 | [] | no_license | require 'spec_helper'
##THESE TESTS ARE NO LONGER WORKING
# I have tried getting factory girl and clean_database to reset the database
# and re-seed it every test, but it still keeps saying that Name has already
# been taken. When I remove that validation from the user model, it just says
# that nil is not a symbol.
... | true |
286b3dbec99c0f32be673c722f02fc3c44d17b9a | Ruby | stulentsev/gt3 | /lib/gt2/line_expander.rb | UTF-8 | 1,190 | 2.859375 | 3 | [] | no_license | class Gt2::LineExpander
def call(lines_obj, &block)
case lines_obj
when Array
lines_obj
when String
@counted_values = block.call
expand_lines_from_string(lines_obj)
else
raise "Unrecognized lines_format: #{lines_obj.inspect}"
end
end
attr_reader :counted_... | true |
90188f9c5e11857927e084cce7ea9a49582ff163 | Ruby | BrianARuff/ruby_practice | /params.rb | UTF-8 | 186 | 3.234375 | 3 | [] | no_license | p 3.between?(1, 5)
p 'cat'.between?('ant', 'dog')
p 'gnu'.between?('a', 'gnt')
def between?(item, start, stop)
return item > start && item < stop
end
puts; p between?('g', 'a', 'b')
| true |
f898a1a32e4414b552d71e88cab2939b792e82eb | Ruby | arnottmj/kudamon | /spec/trainer_spec.rb | UTF-8 | 891 | 3.03125 | 3 | [] | no_license | require 'trainer'
require 'chikapu'
describe Trainer do
subject {Trainer.new('trainer',[0,0])}
let(:chikapu) {Chikapu.new([0,0])}
it 'initializes with a set position' do
expect(subject.position).to eq [0,0]
end
it 'initializes with a set name' do
expect(subject.name).to eq 'trainer'
end
it ... | true |
fa4231b8778de8cf588ec129eee415742fc009e3 | Ruby | Invoca/google-api-ads-ruby | /adwords_api/examples/v201710/campaign_management/graduate_trial.rb | UTF-8 | 3,717 | 2.609375 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
# Encoding: utf-8
#
# Copyright:: Copyright 2016, Google Inc. All Rights Reserved.
#
# License:: 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
#
# ... | true |
1d3c8ff84093eaaf7d2feac1618be06c357d9a37 | Ruby | stve/instapaper | /lib/instapaper/http/response.rb | UTF-8 | 1,616 | 2.828125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'json'
require 'instapaper/error'
module Instapaper
module HTTP
class Response
attr_reader :response, :raw_format, :path
# TODO: Change this to a keyword argument (needs a major version bump)
def initialize(response, path, raw_format = false) # rubocop:disable Style/OptionalBooleanPara... | true |
a0f142b65112f932d1e27e0aff08be016560f3c7 | Ruby | bendee48/hangman-2.0 | /spec/dictionary_spec.rb | UTF-8 | 753 | 2.96875 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../lib/dictionary'
RSpec.describe Dictionary do
subject(:dictionary) { described_class.new(file) }
let(:file) { 'test_file.txt' }
describe '#word' do
it 'returns a string' do
expect(dictionary.word).to be_a String
end
it 'returns a string only... | true |
bef051eb2dc30fd7be5175ed26fa149256e6a46d | Ruby | GatorBoy1/TicketArray | /test_winning_ticket.rb | UTF-8 | 1,091 | 3.671875 | 4 | [] | no_license | #Write a function that takes a 4-digit number as a string, and an array containing winning tickets (also as strings). The function should return and array containing any winning tickets that match your number.
require "minitest/autorun"
require_relative "winning_ticket.rb"
class TestWinningNumbers < Minitest::Test
de... | true |
558e21eb46acf1d057720f164a9fa20486b0a900 | Ruby | hmarcelino/dev-utils | /share/aws/subs/dev-new-instance | UTF-8 | 9,536 | 2.53125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Usage: $_SUB_NAME new-instance -n <name> -c <config_name> [-t <instance_type>] [-p <region>]
# Summary: Creates a new instance in aws.
# Group: AWS
#
# Help: Creates a new instance in aws.
#
# -n|--name: the instance name.
# -c|--config-name: the config name
#
# Optional:
# -t|--type: ... | true |
f00c5677920211f2b11596bb02e8cef567c00aa0 | Ruby | hannaengel/blood-oath-relations-seattle-web-career-042219 | /app/models/Blood_Oath.rb | UTF-8 | 259 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Bloodoath
attr_accessor :cult, :follower, :initiation_date
@@all = []
def initialize(cult, follower, initiation_date)
@cult = cult
@follower = follower
@initiation_date = initiation_date
@@all<< self
end
def self.all
@@all
end
end
| true |
d9cd7af099b3a0020c8742f2b9f1fb6b16361013 | Ruby | progpyftk/learn_to_code_with_ruby_udemy | /Section 3/convert_number_to_strings.rb | UTF-8 | 300 | 3.28125 | 3 | [] | no_license | str = "5"
p str
p str.class
p str.to_i
p str.to_i.class
# notice that these methods does not change the original string:
p str
# converting numbers to strings - it does not change the orignal variable
number = 10
p number.to_s.class
# float to integer, it cuts the float part
pi = 3.14
p pi.to_i
| true |
440462e9ede8c9e5adfb02e62b0fddaa1a359f78 | Ruby | stellamiranda/Billfront | /spec/cli_spec.rb | UTF-8 | 1,967 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
require 'rspec/core'
require 'rspec'
describe "CLI" do
describe "Output" do
it "Should show an error message and exit when no argument passed" do
sample = "We need the parameters to the files\n"
output = `./cli.rb`
expect(output).to eq sample
end
it "Shou... | true |
4ee2890edba229090e6cc2bfbf0513fd753bcfc8 | Ruby | moxiworks-platform/moxiworks-ruby | /lib/moxiworks_platform/office.rb | UTF-8 | 5,582 | 2.5625 | 3 | [] | no_license | module MoxiworksPlatform
# = Moxi Works Platform Office
class Office < MoxiworksPlatform::Resource
# @!attribute moxi_works_office_id
#
# @return [String] the UUID of the office
attr_accessor :moxi_works_office_id
# @!attribute client_office_id
#
# @return [String] This is the ID o... | true |
6dd7c6644c6e4559c20c5649e83cf94069b59e0f | Ruby | johno/iz | /test/test_phone_number.rb | UTF-8 | 562 | 3.015625 | 3 | [
"MIT"
] | permissive | require 'test/unit'
require 'iz'
class TestPhoneNumber < Test::Unit::TestCase
def valid_phone_numbers
['(123) 456-7890', '11234567890', '1 123 456 7890', '123-456-7890']
end
def invalid_phone_numbers
[nil, false, -1, '123456']
end
def test_that_phone_numbers_return_true
valid_phone_numbers.eac... | true |
280fef4b00a7b05a5519e87d7ed70edc587c8cfb | Ruby | thefonso/UNCLEFONSO_lessons | /00-week/ruby_basics/09_blocks_procs_lambdas/02_Blocks_yield_part1.rb | UTF-8 | 511 | 4.375 | 4 | [
"MIT"
] | permissive | # BLOCK PROC LAMBDA: yield part 1
#
# Ruby methods have a way of transferring control from the calling method to the block and back again.
# We can build this into the methods we define by using the "yield" keyword.
def block_test
puts "We're in the method!"
puts "Yielding to the block..."
yield
puts "We're ... | true |
e221d6a2ae63fc8b77a8e7d2d535526ed8939408 | Ruby | nabilhayet/apples-and-holidays-onl01-seng-pt-032320 | /lib/holiday.rb | UTF-8 | 1,120 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def second_supply_for_fourth_of_july(holiday_hash)
holiday_hash[:summer][:fourth_of_july][1]
end
def add_supply_to_winter_holidays(holiday_hash, supply)
holiday_hash[:winter].each do |occasion,val|
val << supply
end
end
def add_supply_to_memorial_day(holiday_hash, supply)
holiday_hash[:spr... | true |
cf6a50ceec8e9960c0866709743c0b9bb69563e6 | Ruby | Marvalero/LearningRuby | /appendix10-solr/.bundle/ruby/2.1.0/gems/outoftime-sunspot-0.9.8/lib/sunspot/dsl/query_facet.rb | UTF-8 | 929 | 2.78125 | 3 | [
"MIT"
] | permissive | module Sunspot
module DSL
#
# This tiny DSL class implements the DSL for the FieldQuery.facet
# method.
#
class QueryFacet
def initialize(query_facet) #:nodoc:
@query_facet = query_facet
end
#
# Add a row to this query facet. The label argument can be anything; i... | true |
2267f8b999060fbb5489e7b7746b84f2eb4708bc | Ruby | lewisisom/ls_rb101 | /lesson_2/rps_bonus_features.rb | UTF-8 | 2,880 | 4 | 4 | [] | no_license | CHOICES = %w(rock paper scissors lizard spock)
CHOICES_SHORTENED = %w(r p s l sp)
WIN_SCORE = 5
WIN_RULES = { 'scissors': ['paper', 'lizard'],
'paper': ['rock', 'spock'],
'rock': ['lizard', 'scissors'],
'lizard': ['spock', 'paper'],
'spock': ['scissors', 'rock'] }... | true |
6859546c054443166b55908034670b6eca845299 | Ruby | hilarysk/daily-feminist-affirmation | /app/models/person.rb | UTF-8 | 1,355 | 2.828125 | 3 | [] | no_license | # Class: Person
#
# Creates different people and gets information about them.
#
# Attributes:
# @person - String: Name of person
# @id - Integer: Person ID, primary key for people table
# @bio - String: Person's biography
# @state - String: State where person was born
# @country - String: Country where pers... | true |
1bdca771ac48294fde45b8f0efa7dcc59a9b377d | Ruby | moskk/rndc | /engine/rndcbase.rb | UTF-8 | 7,325 | 2.734375 | 3 | [] | no_license | #! /usr/bin/ruby
require 'ostruct'
class Job < OpenStruct
attr_reader :log
def initialize()
@log = []
super
end
def url
res = '---'
if not domain.nil?
res = domain[0]
else
res = ip
end
#print self, ' url = ', res
return res
end
def log_event(newlog)
if n... | true |
f5beac2496bbad3008e13a2d43e69340be3672cb | Ruby | john-reiner/ruby-oo-relationships-practice-gym-membership-exercise-nyc-web-012720 | /lib/lifter.rb | UTF-8 | 1,123 | 3.265625 | 3 | [] | no_license | class Lifter
attr_reader :name, :lift_total
@@all = []
def initialize(name, lift_total)
@name = name
@lift_total = lift_total
@@all << self
end
def self.all
@@all
end
def memberships
#list of all the memberships that a specific lifter has
Membership.all.select do |memb|
... | true |
7854ce3760b5ddaea5f8fe0474d588cf43f7e3bd | Ruby | everett1992/maps | /map.rb | UTF-8 | 1,051 | 3.109375 | 3 | [] | no_license | require_relative './dimentions'
class Map
attr_reader :image
include Dimentions
def initialize(image, n: n, s: s, e: e, w: w)
@image = image;
@north = n
@south = s
@east = e
@west = w
add_scale
end
def add_scale
Magick::Draw.new
.stroke('black')
.stroke_width(10)
... | true |
d4aeeda81b75dcb4a57a197d32667b3a25365b83 | Ruby | PenneyGadget/exercisms | /ruby/grains/grains.rb | UTF-8 | 266 | 3.375 | 3 | [] | no_license | class Grains
def self.square(square_num)
2 ** (square_num - 1)
end
def self.total
squares = 64
total = []
until squares == 0
amount = self.square(squares)
total << amount
squares -= 1
end
total.reduce(:+)
end
end
| true |
68eab1580676bee12a44b2017de6496ba782e1a6 | Ruby | cmaher92/launch_school | /coursework/rb100/learn_to_program/factorial_as_integer_class.rb | UTF-8 | 668 | 4.34375 | 4 | [] | no_license | # Factoral as integer class
# The goal here is to modify the Integer class to include the class method factorial
# Factorial is the product of an integer and all the integers below it
# factorial four ( 4! ) = 24
# 4 * 3 * 2 * 1
class Integer
def factorial
current_factorial = [1, 2]
product = current_factori... | true |
ec46c04fb30558f287909805048135a932ab9e1a | Ruby | raen79/tutor_chatbot | /app/models/concerns/question_validator.rb | UTF-8 | 779 | 2.921875 | 3 | [] | no_license | class QuestionValidator < ActiveModel::Validator
def validate(record)
attr_name = options[:attributes].first
unless attr_name.blank? || record[attr_name].blank?
must_end_with_question_mark(record, attr_name)
validate_length(record, attr_name)
end
end
private
def must_end_with_quest... | true |
eec5119572aae0b4b562cc2155cb55c008217ee2 | Ruby | kareemrady/BlackJack | /blackjack_final.rb | UTF-8 | 1,782 | 4.15625 | 4 | [] | no_license |
# Scoring Rules
def card_value(cards)
value_array = cards.map {|card| card[1]}
total = 0
value_array.each do |value|
if value == "A"
total += 11
elsif value.to_i == 0
total += 10
else
total += value.to_i
end
end
total
end
# Creating a deck of cards
suit = ["S", "H", "C", "D"]
cards = ["2","3","4","5",... | true |
bea6a1b4030afa37ecfbe568494257661c17df9e | Ruby | x3ro/derp-xml-formatter | /format.rb | UTF-8 | 2,814 | 3.453125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
if !ARGV[0]
puts "No input file specified. Aborting"
exit 1
end
if !File.exists? ARGV[0]
puts "Please provide a valid file"
exit 1
end
$xml = File.open(ARGV[0], 'r').read
$xml = $xml.gsub("\t", "")
$indent_level = 0
length = $xml.length
$cursor = 0
$debug = false
$outfile = File.open('o... | true |
713479a5031a4cd61c2a9166ad8e911fa0a84cf2 | Ruby | JediMindTricks/Spaces | /app/models/post.rb | UTF-8 | 483 | 2.53125 | 3 | [] | no_license | class Post < ActiveRecord::Base
validates :title, :body, presence: true
belongs_to :user
has_many :taggings, dependent: :destroy
has_many :tags, through: :taggings
delegate :username, to: :user
def self.tagged_with(name)
Tag.find_by!(name:name).posts
end
def all_tags=(names)
# Names = name of tags e.g:... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.