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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
9adde526d877dbd5e346a5d0b98113b529a367fa | Ruby | dylanconnolly/futbol | /lib/game_team_collection.rb | UTF-8 | 4,980 | 3 | 3 | [] | no_license | require 'CSV'
require_relative './game_team'
class GameTeamCollection
attr_reader :game_teams, :game_teams_by_team_id
def self.load_data(path)
game_teams = {}
game_teams_by_team_id = {}
CSV.foreach(path, headers: true, header_converters: :symbol) do |row|
game_team = GameTeam.new(row)
if... | true |
37411ad2bb2063ca6b1fe8415aee4299821fe338 | Ruby | thebetternewt/merge-sort | /merge_sort.rb | UTF-8 | 1,395 | 4.09375 | 4 | [] | no_license | # =============================================================================
# DESCRIPTION: A recursive "merge sort" method written in Ruby.
# USAGE: The merge_sort method takes in an FLAT array of numbers and returns
# a sorted version of the given array.
# ==========================================================... | true |
abde706f9ea25eeec623e191c492b43a5ac220bb | Ruby | TheDesignExchange/app | /db/seeds/casestudies.rb | UTF-8 | 2,422 | 2.703125 | 3 | [] | no_license | require "json"
case_study_file = 'casestudies.json'
# File should be in public
def get_data(json_file)
file = Rails.root.join('public', json_file);
data = JSON.parse( IO.read(file) )
end
def process_companies(data)
Company.destroy_all
p "=============== SEEDING COMPANIES ================"
data.each do |el|
... | true |
26c6010cdebc0c4455ec54eba8c776bf816b4c01 | Ruby | beanieboi/linkdown | /lib/linkdown/parser.rb | UTF-8 | 380 | 2.8125 | 3 | [] | no_license | class Linkdown
class Parser
def initialize(content)
@content = content
@parsed = false
@entries = nil
end
def entries
@entries ||= @content.split("\n").map do |line|
_matches = line.match(/^- \[(.*)\] (.*)$/)
flags = _matches[1]
url = _matches[2]
... | true |
945277782f97241479a00b53d6133a06e9f29208 | Ruby | shaoevans/aA-Classwork | /W2D4/recap_exercise_2/lib/problems.rb | UTF-8 | 3,360 | 4.25 | 4 | [] | no_license | require "byebug"
class String
# Write a method, String#substrings, that takes in a optional length argument
# The method should return an array of the substrings that have the given length.
# If no length is given, return all substrings.
#
# Examples:
#
# "cats".substrings # => ["c", "ca... | true |
c92c2aae15c928d53503d7de3274288e3a63a323 | Ruby | davidmjiang/assignment_association_practice | /association_practice/dependency.rb | UTF-8 | 1,011 | 3.015625 | 3 | [] | no_license | # a user's comments should be more semantic
puts "1"
p User.first.authored_comments
puts "2"
p Comment.first.author
puts "3"
# post authorship should be semantic too
p User.first.authored_posts
puts "4"
p Post.first.authors
puts "5"
# join table
p User.first.post_authorings
puts "6"
p Post.first.post_authorings
puts "7... | true |
cb7401f62f3bfdead1a1ecaf45932bb260d21771 | Ruby | floatplane-dev/ping-rails | /app/controllers/concerns/json_api.rb | UTF-8 | 10,899 | 2.5625 | 3 | [] | no_license | module JsonApi
extend ActiveSupport::Concern
included do
before_action :check_content_type
end
# CRUD
#
# In order to follow the JSON API specs, unsported request endpoints should
# return a 403 forbidden (instead of dropping the request without feedback).
#
# https://jsonapi.org/format/#crud-cr... | true |
b525399a81c73fa9d794b4aa93828f2c2fd1db14 | Ruby | ClaudioLeivaR/introduccion_ruby | /mecanografia/spec/generador_texto_spec.rb | UTF-8 | 658 | 2.890625 | 3 | [] | no_license | require_relative "../lib/generador_texto"
RSpec.describe GeneradorTexto do
it "con solo letras" do
#preparacion
#ejecucion
resultado_letras = GeneradorTexto.letras(10)
#["f","j","f","j","f","j","f","j","f","j"]
#pruebas
expect(resultado_letras.count).to eq(10)... | true |
6e6b21e9f7b467a1d2429f72692e03f87bddcdcf | Ruby | kamilam1987/hw-ruby-intro | /lib/ruby_intro.rb | UTF-8 | 3,923 | 4.28125 | 4 | [] | no_license | # When done, submit this entire file to the autograder.
# Author: Kamila Michel
# Student id: g00340498
# ================================== Part 1 ===================================
# ============================ Arrays, Hashes, and Enumerables ================
=begin
Define a method sum(array) that takes an array... | true |
349837b267e273a506c369d305de331b23663ac8 | Ruby | irenemachine/sales_tax | /spec/receipt_spec.rb | UTF-8 | 1,873 | 3.03125 | 3 | [] | no_license | require 'spec_helper'
describe "Receipt" do
describe "new" do
it "should create a new receipt object with no items" do
receipt = Receipt.new
receipt.instance_variable_get(:@items).empty?.should be_true
end
end
describe "print" do
context "it should print one line per item" do
it "sh... | true |
9db128dad6a954dad37cccc3e46367a284ce0730 | Ruby | taiyoslime/procon | /AOJ/1129.rb | UTF-8 | 151 | 2.9375 | 3 | [] | no_license | while (n,r = gets.split.map(&:to_i)) != [0,0]
a = [*1..n].reverse
r.times {
p,c = gets.split.map(&:to_i)
a = a.slice!(p-1,c)+a
}
puts a[0]
end
| true |
f86063a38d07bd886eefb0b1198e42ab985f3663 | Ruby | kalz2q/elm-examples | /shiritori.rb | UTF-8 | 2,494 | 3.78125 | 4 | [
"MIT"
] | permissive | #buta014.dicを使ったしりとり。最初はランダムに[れ]>とか出して、れんぎょう。とか答えると、次は[う]>うま、[ま]>でプロンプト。そんな感じ。
# $KCODE="s"
dictionary = []
File.open("buta014.dic") { |f|
f.each do |word|
word.strip!
dictionary.push(word)
end
}
def char_rand(aiueo)
aiueo[rand(aiueo.length)]
end
aiueo = %w(
あ い う え お か き く け こ さ し す せ そ た ち つ て と な に... | true |
76558f719d999baeb5ded460425efc0fe0477e02 | Ruby | jyang2017/cs83r | /unit_05/project1.rb | UTF-8 | 6,378 | 3.53125 | 4 | [] | no_license | =begin
Author: Fedorov Igor
Course Number: CS83R_1724
Date: October 4, 2015
Purpose: Create a Ruby program which calculates student fees for those attending
Santa Monica College.
SANTA MONICA COLLEGE STUDENT FEES (as of Fall, 2015):
---------------------------------------------------------------------... | true |
721671810169915c5a19684043b09da743399d1a | Ruby | jgroeneveld/mensr | /app/controllers/fetch_controller.rb | UTF-8 | 3,747 | 2.71875 | 3 | [] | no_license | require 'open-uri'
require 'iconv'
class FetchController < ApplicationController
before_filter :authenticate_user!
DISH_TAG_CONVERTS = {
"Huhn.gif" => :chicken,
"schwein.gif" => :pig,
"Vegetarisch.gif" => :vegetarian,
"Rind.gif" => :cow,
"SunFlower.gif" => :vegan,
"Bio.gif" => :bio,
"L... | true |
de9c37ac76a28dd30ff0f3ae9e25d5d3a300d62a | Ruby | drhuffman12/conway_life | /lib/conway_life/life.rb | UTF-8 | 888 | 3.125 | 3 | [
"MIT"
] | permissive | class Life
def initialize(initial_state)
@state = initial_state
end
def tick
# neighbor_counts = {}
all_cells = Set.new
# next_state = @state.dup
@state.each do |cell|
(-1..1).each do |dx|
(-1..1).each do |dy|
next if [dx, dy] == [0, 0]
all_cells << [cell[0... | true |
c996e75f39e8149742215a288e97694f29dee0c6 | Ruby | reneclavijo/introduccion_ruby | /reforzamiento/juego.rb | UTF-8 | 1,673 | 3.46875 | 3 | [] | no_license | require_relative 'generador_palabras'
class Juego
attr_reader :palabra_secreta
attr_reader :vidas
def initialize
# relación de asosiación / dependencia
@palabra_secreta = GeneradorPalabras.generar
@vidas = 5
end
def comenzar
puts "Bienvenido al ahorcado ☠, adivina... | true |
40495a908aefad0f6e5676f868ece81f455c5fb0 | Ruby | romaindeveaud/wave-robot-ruby-client | /lib/model.rb | UTF-8 | 711 | 2.578125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/ruby
# Defines classes that represent parts of the common wave model.
#
# Defines the core data structures for the common wave model. At this level,
# models are read-only but can be modified through operations.
#
# Note that model attributes break the typical style by providing lower
# camel-cased character... | true |
9bb76c9ad4be744c47b732be7662a420009bea9d | Ruby | phallguy/shamu | /lib/shamu/attributes/equality.rb | UTF-8 | 2,219 | 3 | 3 | [
"MIT"
] | permissive | module Shamu
module Attributes
# Override equality methods to support shallow comparison of attribute
# values for equality.
#
# Add `ignore_equality: true` to any {Attributes::DSL#attribute} that
# shouldn't be included in equality comparisons.
module Equality
# @param [Attributes] ot... | true |
530be3a57ed5cd7990e8bbfa78167cf9370a16c4 | Ruby | PlasticLizard/wonkavision-client | /lib/wonkavision_client/member_filter.rb | UTF-8 | 2,617 | 2.859375 | 3 | [] | no_license | require "time"
module Wonkavision
class Client
class MemberFilter
include Comparable
attr_reader :name, :operator, :member_type
attr_accessor :value
def initialize(member_name, options={})
@name = member_name
@attribute_name = options[:attribute_name]
@operator =... | true |
38b6b8e60567441df3b827bc25a84bbead30065c | Ruby | chiragagrawal/hackathon | /question1.rb | UTF-8 | 640 | 3.84375 | 4 | [] | no_license | class PlayWithArray
def count(string, substring)
count = string.each_char.each_cons(substring.size).map(&:join).count(substring)
puts "the occurence of the subtring is #{count}"
string_array = string.split(' ')
string_array.delete_if do |element|
if element == substring
true # Mstring_arrayke... | true |
54b3866c22200c909f5ca520d0d26249dee0cece | Ruby | YWHo/ruby_language | /c048_file_io.rb | UTF-8 | 1,255 | 3.984375 | 4 | [] | no_license | #!/usr/bin/ruby
## 'puts' statement
puts "-- 'puts' statement --"
val1 = "This is variable one"
val2 = "This is variable two"
puts val1
puts val2
## 'gets' statement
puts "\n-- 'gets' statement --"
puts "Enter a value :"
val = gets
puts "You entered: #{val}"
## 'putc' statement
puts "\n-- 'putc' statement --"
str = ... | true |
ec561c93822ccd9c19dd04940412e45499aab8c1 | Ruby | julianborrey/TabHub | /app/helpers/room_helper.rb | UTF-8 | 1,532 | 2.59375 | 3 | [] | no_license | module RoomHelper
#true is the user is in the tab room of a current tournament for thei institution
def authorized_for_room
#check that this room is in their tournament
#and that this is a tournament they are in the tab room for
@tournament = nil;
if params["tournament_id"] != nil
... | true |
6d9a6f5a92ce06dd9a88ea6053cdda1e3af87fe3 | Ruby | c11nathanjanssen/CBA | /lib/content_items/content_item.rb | UTF-8 | 6,567 | 2.59375 | 3 | [] | no_license | # The ContentItem-class within this module can be used to make any model in
# your application to be 'blogabble'. Just derive from ContentItems::ContentItem
module ContentItem
def self.included(base)
base.extend ContentItem::ClassMethods
end
module_function
# Render :txt as markdown with Redcarpet
def ... | true |
1166fca595fe6f3614e8de6a0fb1e8f0e65c9bd5 | Ruby | Diazware12/GIGIH_BE_Bangsa | /module4/session3/Homework_this_session/spec/check_model_category_spec.rb | UTF-8 | 4,611 | 2.828125 | 3 | [] | no_license | require_relative '../model/categories'
require_relative '../model/items'
require_relative '../model/item_categories'
require_relative '../db/db_connector'
describe Category do
# =================== valid initialize =====================
describe '#validInitCategory' do
context 'init input category' ... | true |
ab259a74dd590721559e94e535eedb84d07b5491 | Ruby | aadeschamps/learning | /Code/Old_week_view/w06/d03/state.rb | UTF-8 | 642 | 4.0625 | 4 | [] | no_license | # puts "What state are you from?"
# state = gets.chomp.upcase
# if state == "NY"
# puts "Welcome to the Empire State"
# elsif state == "NJ"
# puts "You must merge well"
# else
# puts "Where is #{state}?"
# end
# i=0
# while i<10
# puts i
# i += 1
# end
# numbers = [1,2,3,4,5]
# for number in numbers
# puts numb... | true |
0f3455b752e4dc498a56d1cc4e25d332cc1f3757 | Ruby | ebetancourt/admin-scripts | /svn-prompt.rb | UTF-8 | 1,000 | 3 | 3 | [] | no_license | #!/usr/bin/env ruby
# This is a script that does an SVN list of a given directory
# (ideally to list available builds to push, designed to integrate with phing)
require 'rubygems'
require 'smart_colored/extend'
module LastN
def last(n)
self[-n,n]
end
def trim()
self.strip! || self
end
end
class S... | true |
52f5386cda66bf1d37c471175b85906dbd33ef77 | Ruby | heatherm/sheepshead | /app/models/hand.rb | UTF-8 | 817 | 2.71875 | 3 | [] | no_license | class Hand < ActiveRecord::Base
attr_accessible :game_player_id, :card_one_id, :card_two_id, :card_three_id, :card_four_id, :card_five_id, :card_six_id, :position
def cards
[Card.find(card_one_id), Card.find(card_two_id), Card.find(card_three_id), Card.find(card_four_id), Card.find(card_five_id), Card.find(car... | true |
ad495a72cc514b84e163a105e7f864be53a2e23f | Ruby | BrittBarrow/method-scope-lab-dc-web-042318 | /lib/catch_phrase.rb | UTF-8 | 45 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def catch_phrase (phrase)
puts phrase
end
| true |
cdffcb0f787f346fbc3b4b249ce1f6ac941245e7 | Ruby | ldfren/WeiyouxiRubySDK | /WeiyouxiClient.rb | UTF-8 | 5,802 | 2.578125 | 3 | [] | no_license | ##
# Ruby API for Sina MicroBlog Weiyouxi,
# developped on Ruby 1.9.3, and tested on Rails 3.2.3
# By Lead Frenzy (ldfren@gmail.com) MSN:ldfren@hotmail.com QQ:20294415 http://leadfrenzy.net
# 2012.04.08 v0.0.2
##
## Sample: use it to get user infor in Rails controller
# require 'WeiyouxiClient'
# # define your ... | true |
2d58475470f2d28947df82e974cde52623bdd13f | Ruby | raulvillalonga/week2 | /day1/ejerTodo/spec/todo_spec.rb | UTF-8 | 966 | 2.859375 | 3 | [] | no_license | require_relative '../todo.rb'
RSpec.describe "Task checker" do
before :each do
@create_task = Task.new("Walk the dog")
end
it "class create" do
expect(@create_task.content).to eq("Walk the dog")
end
it "class id 2" do
expect(@create_task.id).to eq(2)
end
it "complete?" do
expect(@... | true |
98f0568ebf82b01d2c191cfc50da84f26ea2be95 | Ruby | cmccandless/ExercismSolutions-ruby | /rotational-cipher/rotational_cipher.rb | UTF-8 | 243 | 3.3125 | 3 | [
"MIT"
] | permissive | class RotationalCipher
def self.rotate(plaintext, num)
plaintext.chars.collect { |char|
base = (char =~ /[A-Z]/ ? 'A' : 'a').ord
char =~ /[A-Za-z]/ ? ((char.ord - base + num + 26) % 26 + base).chr : char
}.join
end
end
| true |
d2f322c01747af9580276ef7740b8075bfd90c3d | Ruby | AtsushiNi/gakuren | /app/models/livescore/match.rb | UTF-8 | 1,484 | 2.875 | 3 | [] | no_license | class Match < ApplicationRecord
after_initialize :init_score
def get_score
self.score.split(/set/).map do |set|
set.split(/-/)
end
end
def finish?
set_results = self.get_score.map do |set|
if (set[0].to_i == 6 && set[1].to_i < 5) || set[0].to_i == 7
0
elsif (set[1].to_i =... | true |
c069b86abad5d90cc0cf68db2679209754b88634 | Ruby | Rama0210/oo-cash-register-online-web-pt-081219 | /lib/cash_register.rb | UTF-8 | 817 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
require "pry"
class CashRegister
attr_accessor :total, :items, :with_discount, :last_transaction_amount
def initialize(with_discount = 0)
@total = 0
@with_discount = with_discount
@items = []
end
def discount
self.with_discount
end
def add_item(title,price,quantity = 1)
@total += price*quantity
quantity.times d... | true |
54972d76fde2b2683e2c733cbc3b29c5f6399e3a | Ruby | itsolutionscorp/AutoStyle-Clustering | /assignments/ruby/combine_anagrams/src/17114.rb | UTF-8 | 364 | 3.046875 | 3 | [] | no_license | def combine_anagrams(words)
words_already_selected = ""
result = []
words.each do |w|
next if words_already_selected.include?(w)
group = words.select do |x|
x.downcase.chars.sort.join.eql?(w.downcase.chars.sort.join)
end
words_already_selected = (words_already_selected + group.join("|"))
... | true |
fada4e740715748931c83359b472fa5b5c625033 | Ruby | oumiya/click_rpg | /scripts/Avater_Armor_Data.rb | UTF-8 | 1,629 | 2.890625 | 3 | [] | no_license | # イベント用アバターの防具データクラス
class Avater_Armor_Data
# 防具データをハッシュの配列で定義
def initialize()
@armor = Array.new
@armor.push({:filename=>"clothes.png"})
@armor.push({:filename=>"leather.png"})
@armor.push({:filename=>"plywood.png"})
@armor.push({:filename=>"scales.png"})
@armor.push({:filename=>"chain.p... | true |
b1f6ba993c5e259a0328338a21bcb6763204c7de | Ruby | ltrainpr/Katas | /Bowling Game/bowling_game.rb | UTF-8 | 631 | 3.515625 | 4 | [] | no_license | class Game
def initialize
@score = []
@rolls = []
@frame = 0
@counter = 0
end
def roll(pins)
@rolls << pins
end
def score
10.times do
if roll_score == 10
@frame = 10 + roll_score(1) + roll_score(2)
add_frame
next_frame(1)
next
elsif frame == 10
@frame = 10 + roll_score(2... | true |
94f4b69ba11204d93972585594ad78632c82368b | Ruby | braydon322/ruby-class-variables-and-class-methods-lab-v-000 | /lib/song.rb | UTF-8 | 1,253 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
@@count = 0
@@artists = []
@@genres = []
@@songs = []
@@artist_count = {}
@@genre_count = {}
@@genre_counter = 0
@@artist_counter = 0
attr_accessor :name, :artist, :genre
def initialize(songName, artist, genre)
@@count += 1
@songName = songName
@artist = ar... | true |
cc0207f054bd4c17435db0fbdfacc98f8a68b5d3 | Ruby | mrkn/mxnet.rb | /lib/mxnet/gluon/data/dataset.rb | UTF-8 | 1,841 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'mxnet/gluon/data'
module MXNet::Gluon::Data
class Dataset
include Enumerable
def length
raise NotImplementedError
end
def [](idx)
raise NotImplementedError
end
def each
return enum_for unless block_given?
i = 0
while i < length
yield self[i]
... | true |
c3f83b646faadc565a1d6bba6bd92f70e2a21439 | Ruby | alexgenco/modifiers | /spec/modifiers/define_modifier_spec.rb | UTF-8 | 431 | 2.828125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'modifiers/define_modifier'
module MyModifier
extend Modifiers
define_modifier(:bro) { |i| i.invoke + ', bro' }
end
class Foo
extend MyModifier
bro def hello(name = 'world')
"hello, #{name}"
end
end
RSpec.describe Modifiers do
describe '.define_modifier' do
it 'can ... | true |
4d3d8c645e68b0690ab417d1539742db4ae392b6 | Ruby | CollectiveLearning/SearchingVowels | /yvalenta/parallel_search.rb | UTF-8 | 911 | 3.5 | 4 | [] | no_license | class SearchVowels
def initialize
@time ||= { start: 0, finish: 0 }
end
def open_file
f = File.open(File.dirname(__FILE__) + "/../text.txt")
run(f)
end
private
def vowels
@vowels ||= { "a" => 0, "e" => 0, "i" => 0, "o" => 0, "u" => 0 }
end
def run(file)
threads = []
@time[:st... | true |
00ef5e53567aa47413bd5efa4f2d4c6915d9ffdd | Ruby | marioatpb/advent_of_code | /2020/08/machine.rb | UTF-8 | 1,350 | 3.34375 | 3 | [] | no_license | require 'set'
module Advent
class Machine
attr_reader :inst
def initialize(input)
@inst = input.each_line.map do |line|
cmd, val = line.chomp.split(" ")
val = val.to_i
[cmd, val]
end
end
def run(instructions = inst, raise_error = false, acc = 0, idx = 0, visited... | true |
297613e4d290f84c40b0020e76717464d8935abf | Ruby | anneslin/fa16-hw1 | /foobar.rb | UTF-8 | 230 | 3.265625 | 3 | [] | no_license | class Foobar
def self.baz(a)
# Class method
# Call with `Foobar.baz`
a.map!{|element| element.to_i + 2}
a.select!{|i| i % 2 == 0}
a.uniq!
a.reject!{|i| i > 10}
a.inject{|sum, i| sum + i}
end
end
| true |
cd54fc1d347da364ce63d73971e422f835f89052 | Ruby | kupolak/codewars | /Ruby/8 KYU/Object Oriented Piracy.rb | UTF-8 | 159 | 2.90625 | 3 | [] | no_license | class Ship
def initialize(draft,crew)
@draft=draft
@crew=crew
end
def is_worth_it
w = @draft - @crew*1.5
w > 20 ? true : false
end
end | true |
35741509cff59364cde6e4a01370f1902fef643e | Ruby | kipcole9/rainbow | /lib/rainbow/color/harmony/lch.rb | UTF-8 | 1,781 | 2.984375 | 3 | [
"MIT"
] | permissive | module Rainbow
module Color
module Harmony
class LCH
def self.complement(color)
lch = color.to_lch
hue = (lch.h + 180) % 360
[
Color::LCH.new(lch.l, lch.c, hue)
]
end
def self.split_complement(color)
lch = color.t... | true |
60a4814d9353bf09d6b0d655358f8dd9b57b989a | Ruby | philm1873/Homework_Week02_Day01 | /specs/classes_part_a_spec.rb | UTF-8 | 1,049 | 3.03125 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../classes_part_a.rb')
class TestClassesPartA < MiniTest::Test
def test_student_name
student = Student.new("Phil Mitchell", 17)
assert_equal("Phil Mitchell", student.student_name)
end
def test_student_cohort
student = Student.new("... | true |
a709fbb7643576e6a585fcb594bf841adf0e33a2 | Ruby | pathakg028/terminal_app_ruby | /ticket_engine.rb | UTF-8 | 6,837 | 3.421875 | 3 | [] | no_license | require 'csv'
class Person
attr_accessor :name, :email, :number_of_persons
def initialize(name, email, number_of_persons)
@name = name
@email = email
@number_of_persons = number_of_persons
end
def create_hash()
@person_hash = {:name=>@name,:email=>@email,:number_of_persons=>@number_... | true |
1988c65864c5e696da45ed0ad3fb69e965c76c15 | Ruby | hellostealth/stealth | /lib/stealth/configuration.rb | UTF-8 | 1,035 | 2.984375 | 3 | [
"MIT"
] | permissive | # coding: utf-8
# frozen_string_literal: true
module Stealth
class Configuration < Hash
def initialize(hash)
hash.each do |k, v|
self[k] = store(v)
end
self
end
def method_missing(method, *args)
key = create_config_attribute(method)
if setter?(method)
sel... | true |
253bb433476ac5567271967e721d3c983b5a5063 | Ruby | pgengler/ip-tracker | /relative_date.rb | UTF-8 | 727 | 3.125 | 3 | [
"MIT"
] | permissive | # adapted from http://stackoverflow.com/a/195894/391999
module RelativeDate
def to_relative
a = (Time.now-self).to_i
case a
when 0 then 'just now'
when 1 then 'a second ago'
when 2..59 then a.to_s+' seconds ago'
when 60..119 then 'a minute ago' #120 = 2 minutes
when 120..3540 then (a/60).to_i.to_s... | true |
d7128eac545a13530142d5c56b1077bb7e6154fd | Ruby | TY231618/springer-tech-test | /lib/canvas.rb | UTF-8 | 541 | 3.453125 | 3 | [] | no_license | class Canvas
attr_reader :inside_area, :width
def initialize(height, width)
@inside_area = Array.new(height) { Array.new(width, " ") }
@width = width
end
def display
border_sides
border_top_and_bottom
inside_area.each {|element| puts element.join}
end
private
def border_sides
... | true |
afe53356612b62a34f64b8054b04cf0372fb3da8 | Ruby | MyToolsCom/tierion | /lib/tierion/hash_api/receipt.rb | UTF-8 | 3,563 | 2.6875 | 3 | [
"MIT"
] | permissive | module Tierion
module HashApi
class Receipt < Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::MethodAccess
include Hashie::Extensions::IndifferentAccess
def to_pretty_json
puts JSON.pretty_generate(self)
end
def confirmations
get_... | true |
9c5e7d90f0ed783cec133bc51fda4ead1313e3b4 | Ruby | teddyviking/CleverChessValidator | /lib/chess.rb | UTF-8 | 1,005 | 3.703125 | 4 | [] | no_license | require 'pry'
RULES = {
p: [Proc.new { |orig, dest| orig[0] != dest[0] },
Proc.new { |orig, dest| dest[1] - orig[1] != 1 }],
r: [Proc.new { |orig, dest| orig[0] != dest[0] && orig[1] != dest[1] }],
b: [Proc.new { |orig, dest| orig[0] == dest[0] || orig[1] == dest[1] },
Proc.new { |orig, dest| (orig[0... | true |
19f8d02ad9a4e749e99412016351528d1eccf5ae | Ruby | Hakkonen/RubyChain | /Main/node/block.rb | UTF-8 | 2,308 | 3.0625 | 3 | [] | no_license | # The block class
require "digest"
require "pp"
require "json"
# MAKE USAGE DOCUMENT
# TODO: Fix time issue
class Block
attr_reader :id
attr_reader :hash
attr_reader :prev_hash
attr_reader :time_stamp
attr_reader :nonce
attr_reader :merkle_r
attr_reader :data
attr_reader :difficulty
... | true |
715a34b88900d98667e81fb7bc6636c4b1759332 | Ruby | nat-n/neuroanatomist | /app/models/type.rb | UTF-8 | 1,242 | 2.515625 | 3 | [] | no_license | class Type < ActiveRecord::Base
belongs_to :supertype, :class_name => "Type"
has_many :subtypes, :class_name => "Type", :foreign_key => "supertype_id"
has_many :things
has_many :subject_relations, :class_name => 'Relation', :foreign_key => 'subject_type_id', :dependent => :destroy
has_many :objec... | true |
1a3101212630fd2d85d96676b87182795e673d83 | Ruby | AnnaErshova/todos | /todo23/fakearray.rb | UTF-8 | 886 | 4.21875 | 4 | [] | no_license | # To explore the confusion around the results object we get back from queries using the mysql2 gem...
# Create an object that behaves like an array but is NOT an array. Define the each, first and indexing methods on it.
# I should get the same result if i do
# container = []
# [1,2,3].each { |element| container << e... | true |
29b77e99954dfabfe2704257a9a37a12d20edd84 | Ruby | MikeDacanay/ruby_project | /project_spec.rb | UTF-8 | 624 | 2.875 | 3 | [] | no_license | require_relative 'project' # include our Project class in our spec file
RSpec.describe Project do
before(:each) do
@project1 = Project.new('Project 1', 'desc 1', 'John')
end
it 'has a method elevator_pitch to explain name description' do
expect(@project1.elevator_pitch).to eq('Project 1, desc 1')
... | true |
9f413245132cb43fdf035a09cf5008a4d7a2e359 | Ruby | aoliver6/ruby_building_blocks | /substrings.rb | UTF-8 | 860 | 4.03125 | 4 | [] | no_license | dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]
#Takes a string and an array containing several words
#Splits the string into an array and matches the string
#to words in the array. It then stores the number of matches in
#a hash and displays them to the scr... | true |
6fc5a80018ae08978cd89fb345869d0380ed25d4 | Ruby | yuanying/dir_image | /lib/filesystem.rb | UTF-8 | 1,198 | 2.703125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'rack'
require 'fileutils'
class Filesystem
def self.init config
@config = config
end
def self.config
@config
end
def self.directory? index, path
File.directory?(self.real_path(index, path))
end
def self.real_path index, path
File.join(Filesystem.image_dir(index), path)
end
... | true |
8809aa168f38b9428b0c23ddad10f48ac686d91f | Ruby | Noura-alhindi/hw_week_07_day_02_ruby_MTA | /MTA.rb | UTF-8 | 1,571 | 3.640625 | 4 | [] | no_license | $mta= {
line_n: ["Times Square", "34th", "28th", "23rd", "Union Square", "8th"],
line_l: ["8th", "6th", "Union Square", "3rd", "1st"],
line_6: ["Grand Central", "33rd", "28th", "23rd", "Union Square", "Astor Place"],
}
$stops = 0
def one_line(line_name, start_stop, end_stop)
lines = $mta[line_name]
result = []
i... | true |
30808900b6712fe716caa4087969bf0b902e8139 | Ruby | nhatho89/Chess-AppAcademy | /Queen.rb | UTF-8 | 436 | 3.328125 | 3 | [] | no_license | require_relative "SlidingMove"
require_relative 'Piece'
class Queen < Piece
include SlidingMove
attr_reader :color, :symbol, :board
def initialize(color,board)
super(color, board)
@symbol = " ♕ "
@board = board.deep_dup
end
def valid_move?(start, ending)
axis_valid_move?(start, ending) || d... | true |
54626bd939dfd10eec2628212a16fcf17dc706ce | Ruby | mattharbo/soccerresults | /app/controllers/games_controller.rb | UTF-8 | 3,603 | 2.703125 | 3 | [] | no_license | require 'uri'
require 'net/http'
require 'openssl'
require 'json'
require 'time'
class GamesController < ApplicationController
def show
@thedate = params[:id]
# Code test with an API call • "Ligue 1" league is 525
####################################
# Game IDs recovery based on date
#########... | true |
b2f41c36ff08de8758ac1ecde1c66d67c507c196 | Ruby | WillieShubert/DojoAssignments | /Ruby/Ruby_Fun/module_practice/animals/mammal.rb | UTF-8 | 286 | 3.65625 | 4 | [] | no_license | puts 'I am in the mammal file'
class Mammal
attr_accessor :name, :health
def initialize(name)
@name = name
@health = 150
end
def display_health
puts "Name: #{@name}"
puts "Health Level: #{@health}"
end
end
zebra = Mammal.new("Dave")
zebra.display_health | true |
2e378775672ec63e2b71909df2a2a0c860fca021 | Ruby | enyia21/reverse-each-word-onl01-seng-ft-041320 | /reverse_each_word.rb | UTF-8 | 341 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # def reverse_each_word(sentence)
# reversed = []
# reversed_sencence = ""
# (sentence.split).each do|word|
# reversed << word.reverse
# end
# return reversed.join(" ")
# end
def reverse_each_word(sentence)
reversed = []
reversed << (sentence.split).collect do|word|
word.reverse
end
return re... | true |
82e41b0fbb551a0c73cf212a15d8c8219ac56f3d | Ruby | sumanpali/Classes | /box_class.rb | UTF-8 | 183 | 3.171875 | 3 | [] | no_license | class Box_Class
def initialize (w,h)
@width=w
@height=h
end
def display_values
p @width
p @height
end
end
box_obj=Box_Class.new(10,20)
box_obj.display_values | true |
1daaba9fb4934db21456c0d687773149fd5a0df5 | Ruby | rolme/workbase | /app/helpers/navigation_helper.rb | UTF-8 | 748 | 2.59375 | 3 | [] | no_license | module NavigationHelper
def nav_link(text, path, options = {})
classes = nav_link_class_name(path, options)
classes = "#{classes} #{options[:class]}".squish
content_tag "li", class: classes do
link_to nav_link_content(text, options), path
end
end
def get_active_class(contoller_name, menu)... | true |
867b908fee2285cce1e35d5e4f8f81c36165e0d9 | Ruby | D-coder22/Ruby-Udemy | /Blocks, Procs,Lamdas - Section 14/lambdas_intro.rb | UTF-8 | 377 | 3.5625 | 4 | [
"MIT"
] | permissive | sq_proc= Proc.new {|num| num**2 }
sq_lamda= lambda{|num| num**2 }
p [1,2,3].map(&sq_proc)
puts
p [1,2,3].map(&sq_lamda)
p sq_lamda.call(5)
some_prc=Proc.new{ |name,age| "Your name is #{name} and your age is #{age}"}
p some_prc.call("Boris",25)
p some_prc.call("Boris")
some_lmd=lambda{ |name,age| "Your name is #{nam... | true |
706da5a2867561d7ea3ef4f0ae083712b0d16f8d | Ruby | thestokkan/RB100 | /exercises_ruby_basics/conditionals/weather.rb | UTF-8 | 1,235 | 4.4375 | 4 | [] | no_license |
puts "Unpredictable Weather (Part 1)"
# In the code below, sun is randomly assigned as 'visible' or 'hidden'.
sun = ['visible', 'hidden'].sample
# Write an if statement that prints "The sun is so bright!" if sun equals 'visible'.
# Answer (CORRECT):
if sun == 'visible'
puts 'The sun is so bright!'
end
puts "... | true |
9dd1185f714a93e75247c1ce1461e3945fc75652 | Ruby | BeatrizLino/DesafioSemanais | /Questao_007.rb | UTF-8 | 181 | 3.859375 | 4 | [] | no_license | v = Array.new
puts "Números do array:"
(0..9).each {|i| v[i] = i+1}
puts "#{v}"
puts "\nNúmeros maior que 5:"
v.each do |item|
if item > 5
puts "#{item}"
end
end | true |
d3be03100ae41360b6544a78a20f5d3b011bbed7 | Ruby | 2called-chaos/bouncefetch | /lib/bouncefetch/application/statistics.rb | UTF-8 | 1,676 | 3.15625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Bouncefetch
class Application
class Statistics
attr_reader :storage
def initialize
@storage = {}
end
def add key, opts = {}, &block
@storage[key.to_sym] = {
display: true,
value: 0,
name: key.to_s.gsub("_", " "),
callback: bl... | true |
21731deda9ad25a629fc41f02ef5dda2796fc1d6 | Ruby | Tsiory-prdx/Premier_essai_ruby | /Exo20.rb | UTF-8 | 247 | 3.515625 | 4 | [] | no_license | puts "Combien d'etages voulez vous pour la pyramide?"
print ">"
etage = gets.to_i
diese = "#"
puts "Voici la pyramide :"
if etage >= 1 && etage <= 25
for i in (1..etage)
puts diese * i
end
else puts "c'est seulement entre 1 et 25"
end | true |
3e4e32385babf1faecae8bf3b3a6c1a255b752d1 | Ruby | jalanda/l2cwork | /chp6-1.rb | UTF-8 | 525 | 2.921875 | 3 | [] | no_license | line_width = 50
puts ( 'Old Mother Hubbad'.center(line_width))
puts ( 'Sat in her cupboard'.center(line_width))
puts ( 'Eating her curds and whey'.center(line_width))
puts ( 'When along came a spider'.center(line_width))
puts ( 'Who sat down beside her'.center(line_width))
puts ( 'And scared her ppor shoe dog away.'.ce... | true |
c07e966bed590aa0395cc9d29af61469395871c3 | Ruby | TJM/cpldl | /app/models/export.rb | UTF-8 | 593 | 2.609375 | 3 | [] | no_license | require "csv"
class Export < ActiveRecord::Base
def self.to_csv_for_completion_report(data)
CSV.generate do |csv|
csv << ["Zip Code", "Sign-Ups(total)", "Course Title", "Completions"]
data.each do |zip_code, info|
zip_code = zip_code
sign_ups = info[:sign_ups]
values = [zip_c... | true |
ae1fc77a950b555df93946d0a6437c477dab835d | Ruby | epoch/appleandroids | /04-ruby/ruby_intro/hashes.rb | UTF-8 | 435 | 3.34375 | 3 | [] | no_license | require 'pry'
# new syntas for hashes
song1 = {
title: 'hello',
artist: 'Lionel Richie',
released: 1983
}
# original syntax hashes
song2 = {
:title => "nothings gonna change my love for you",
:artist => 'glen medeiros',
:released => 1986
}
song3 = {
'title' => 'a whole new world',
'artist' => 'disn... | true |
532997b567bc82bf83d4d21fe64b856d09b0bc2f | Ruby | cr1tterp0wer/knights-and-moves | /skeleton/Knight-Travails/knight.rb | UTF-8 | 1,165 | 3.359375 | 3 | [] | no_license |
require_relative 'board.rb'
require 'byebug'
class KnightPathFinder
attr_reader :board, :start_pos
def initialize(pos)
@board = Board.new
@start_pos = pos
@visited_positions = [pos]
end
def find_path(end_pos)
current_node = @board[@start_pos]
node_list = [current_node]
until node_li... | true |
a16f0058ca69297a70f4e31c90a1ce8479692ce7 | Ruby | ehedaoo/ascension | /lib/ascension/ext.rb | UTF-8 | 230 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | class Array
def sum
inject { |s,i| s + i }
end
end
class Object
def klass
self.class
end
end
class Array
def uniq_by
res = {}
each do |obj|
res[yield(obj)] ||= obj
end
res.values
end
end | true |
92cf9ad854ea7dca577435c429cce4519ec81140 | Ruby | ElonPark/Ruby | /pickaxe/ch4-1.rb | UTF-8 | 5,587 | 3.65625 | 4 | [] | no_license | # 실제로 사용되는 대부분의 프로그램은 데이터 컬렉션을 처리한다.
# 루비에는 컬렉션을 다루기 위한 배열과 해시라는 두개의 내장 클래스가 준비되어 있다.
# 이 두 클래스에 익숙해지는 것이 실력 있는 루비 프로그래머가 되는 지름길이다.
# 두 클래스는 매우 다양한다 기능을 제공하므로 이를 전부 익히는 데는 상당한 시간을 필요로 한다.
# 하지만 루비에서 컬렉션을 다루기 위한 클래스가 배열과 해시만 있는 것이 아니다.
# 루비에는 코드 덩어리를 캡슐화할 수 있도록 도와주는 블록이는 문법이 있다.
# 블록과 컬레션을 함께 사용하면 강력한 반복자 구문이 된다.
... | true |
32a5452be3ca56a20a34907f68396aec6163db10 | Ruby | rosanarezende/CampusCode | /TreinaDev/OO/0.versoes_anteriores/2.poucasClasses/lib/file_processor.rb | UTF-8 | 2,432 | 3.625 | 4 | [] | no_license | class FileProcessor
# ========== atributos ==========
attr_reader :file_path
# ========== construtor ==========
def initialize(file_path)
@file_path = file_path
# metodo_privado() # podemos chamar um método privado direto no construtor, mas é algo atípico
end
# ========== métodos públicos ========... | true |
59f1d37046c82d2d3976589b8559a7a83431fe8a | Ruby | leo-clubs/marozi | /lib/import/club_importer.rb | UTF-8 | 1,238 | 2.78125 | 3 | [
"MIT"
] | permissive | require_relative './helper/helper'
module Import
class ClubImporter
include Helper
def initialize node, year = nil
@node = node
@year = year
end
def simple_attribute_mappings
{
'id' => [:oid, integer_lambda],
}
end
def list_element_mappings
{
'... | true |
51478469e0d2d04183bf304f148304934317434e | Ruby | syhsyh9696/Ruby | /Leetcode/search_for_a_range.rb | UTF-8 | 510 | 3.140625 | 3 | [] | no_license | # encoding:utf-8
# @param {Integer[]} nums
# @param {Integer} target
# @return {Integer[]}
def search_range(nums, target)
lbound = nums.bsearch{ |i| i >= target }
return [-1, -1] if lbound.nil?
return [-1, -1] if lbound != target
rbound = Hash[nums.map.with_index.to_a][target]
ret... | true |
c597436f296de44af75b0e9f38a94a525914283f | Ruby | keikishi/solvingJava | /4-30.rb | UTF-8 | 367 | 3.59375 | 4 | [] | no_license | puts "数当てゲーム開始!"
puts "10〜99の数を当ててください"
ans = 10 + rand(90).to_i
while true do
puts "いくつかな:"
n = gets.to_i
if n > ans
puts "もっと小さな数だよ"
elsif n < ans
puts "もっと大きな数だよ"
else
puts "正解です"
exit
end
end | true |
1efbc9c674a237ee96164e80e5a8b9e8a69354ca | Ruby | Tomo-9925/scripts | /telnet_at_regular_intervals.rb | UTF-8 | 1,225 | 3.171875 | 3 | [] | no_license | #!/usr/bin/env ruby
=begin
# このスクリプトについて
実行方法: `ruby [このファイル]`
下記の設定を元にtelnetのセッションを作成し,指定したテキストを送信します
=end
require 'net/telnet'
# 設定(先頭文字を大文字化(定数化)するとエラー)
dst_ip = '192.168.190.2' # 送信先のIPアドレス
dst_port = 80 # 送信先のポート
exp_num = 20 # 送信回数
timeout = 60 # タイムアウトの時間(s)
sleep_time = 5 # 送信間隔(s)
text = "GET / HTTP/1.... | true |
b4300eab50442bd99746e5af514665ba855e8528 | Ruby | Joewebsta/csv_practice | /lib/runner.rb | UTF-8 | 544 | 2.828125 | 3 | [] | no_license | require 'csv'
require './lib/animal_lover'
require './lib/magical_pet'
CSV.foreach('./data/animal_lovers.csv', headers: true, header_converters: :symbol) do |row|
id = row[:id].to_i
first_name = row[:first_name]
last_name = row[:last_name]
age = row[:age]
p AnimalLover.new(id, first_name, last_name, age)
en... | true |
97caef0a45b8bf501c9ba48543bc60b0dead872c | Ruby | yasuhito/ll | /lib/locker.rb | UTF-8 | 2,503 | 2.640625 | 3 | [] | no_license | require "ll"
require "lock"
require "node"
require "resolv"
#
# A Locker class
#
class Locker
def initialize debug_options = {}
@debug_options = debug_options
end
def load_locks data
@data = data
if FileTest.exists?( @data )
@list = Marshal.load( IO.read( @data ) )
else
@list = Has... | true |
2f3ce1311818639e3562ab838e2842afc646cfc9 | Ruby | zorrobyte/comma_api_rb | /example/leaderboard_example.rb | UTF-8 | 257 | 2.625 | 3 | [] | no_license | require_relative '../lib/comma-api-rb'
ladder = CommaAPI::API.leaderboard()
ladder = ladder.f "weekly"
puts "weekly ladder:"
ladder.each_with_index do |user, idx|
puts "#{"%02d" % (idx+1)}) #{user.f("username").ljust 20} (#{user.f "weekly"} points)"
end
| true |
dd18b809ff3106a1da884c8148a562fe5c482502 | Ruby | melindadiaz07/ruby-oo-object-relationships-kickstarter-lab | /lib/backer.rb | UTF-8 | 339 | 2.96875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Backer
attr_reader :name
def initialize(name)
@name = name
end
def back_project(project)
new_pb = ProjectBacker.new(project, self)
end
def backed_projects
pb_int = ProjectBacker.all.select {|pb| pb.backer == self}
pb_int.map {|pb| pb.proj... | true |
9a8aad466e98e36485172efd20a9de714803834b | Ruby | chad/rubinius | /lib/compiler/garnet/bindingagent.rb | UTF-8 | 1,723 | 2.765625 | 3 | [] | no_license | class Compiler::Node
def to_ba
raise Error, "#{self.class} is not supported in binding expressions"
end
class Call
def collapse_args(scope)
unless @arguments.kind_of? Array
raise Error, "Direct arguments are the only support type"
end
args = @arguments.map { |... | true |
b370d2a16333f2958cac257b4588e3868311305a | Ruby | CaptainSpectacular/pos_api | /app/models/price_maker.rb | UTF-8 | 684 | 2.546875 | 3 | [] | no_license | class PriceMaker < ActiveModelSerializers::Model
def initialize(name)
@name = name
end
def info
@info ||= service.get_info(@name)
end
def price
service.get_price(get_condition)[:results][0][:price]
end
def image
info[:results][0][:image]
end
def name
info[:results][0][:pr... | true |
a8fbf55f64f3880258cc153be4f73a2d2ee571c6 | Ruby | maryrosecook/theperceptron | /lib/twfying.rb | UTF-8 | 1,874 | 2.59375 | 3 | [] | no_license | module Twfying
BASE_GET_DEBATES_URL = "http://www.theyworkforyou.com/api/getDebates?key=#{Configuring.get('twfy_api_key')}"
DEFAULT_DEBATE = "commons"
DEFAULT_OUTPUT = "xml"
def self.search_debates(search, mp_name)
statements = []
if Util.ne(search)
# get MP person id if MP specified
mp =... | true |
3061a6cc540f99a9d01a01f1939c4fead52139fc | Ruby | howardbdev/word-of-the-day | /lib/word_of_the_day/scraper.rb | UTF-8 | 2,611 | 2.65625 | 3 | [
"MIT"
] | permissive | class WordOfTheDay::Scraper
def self.scrape_words
scrape_merriam_webster
scrape_dictionary
scrape_wordthink
scrape_wordnik
scrape_thefreedictionary
end
def self.scrape_merriam_webster
doc = Nokogiri::HTML(open("http://www.merriam-webster.com/word-of-the-day"))
definition = ''
doc... | true |
50c854a4715c4bbdf2da9f9dafde1cbde0afe6ae | Ruby | paulcockrell/Unit-auto-scaler | /lib/unit_auto_scaler/base.rb | UTF-8 | 2,180 | 2.703125 | 3 | [] | no_license | class UnitAutoScaler
autoload :Unit, 'unit_auto_scaler/unit'
attr_reader :name, :unit, :value
def initialize(value, unit = nil, args = nil )
case value
when Hash
@unit = Unit.for(value[:unit])
@reference_value = value[:reference_value].to_f || (value[:value] * @unit.value).to_f
... | true |
cfea3290166b696edce9563f987f47bf5e18d9ca | Ruby | ColinTheRobot/mushroom-observer | /app/classes/country_counter.rb | UTF-8 | 1,817 | 2.796875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # encoding: utf-8
#
# = CountryCounter
#
# This class counts how many observations are from each country
#
# == Methods
#
# num_genera:: Number of genera seen.
# num_species:: Number of species seen.
# genera:: List of genera (text_name) seen.
# species:: List of species (text_name) see... | true |
feaed87ff7406fa5d427cb308f2d8a995bbd2132 | Ruby | urbanvas/ttt-game-status-cb-000 | /lib/game_status.rb | UTF-8 | 1,151 | 3.78125 | 4 | [] | no_license | # Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
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 won?(board)
WIN_COMBINATIONS.each do |com|
win_index_1 = c... | true |
908652e0ab0a489481ce2e20fa5c9d86657ca541 | Ruby | eaglerockdude/tealeaf_precoursework | /arrays/x3.rb | UTF-8 | 269 | 3.78125 | 4 | [] | no_license | # ken mcfadden : Tealeaf Academy pre-course exercises
# Arrays Exercise 2 :
# Summary :
# How do you print the word "example" from the following array?
arr = [["test", "hello", "world"],["example", "mem"]]
# print example
puts (arr[1][0])
puts "or"
puts arr.last.first | true |
13afd23d3b8e7a41e7e9d4f5b83c22368e033a44 | Ruby | Bluebie/legs | /lib/legs.rb | UTF-8 | 14,456 | 2.96875 | 3 | [] | no_license | # Legs take you places, a networking companion
['rubygems', 'socket', 'thread'].each { |i| require i }
require 'json' unless self.class.const_defined? 'JSON'
class Legs
# general getters
attr_reader :socket, :parent, :meta
def inspect; "<Legs:#{object_id} Meta: #{@meta.inspect}>"; end
# Legs.new for a clien... | true |
cecb4fc01fa2d4107a0a24dda4c2b6986d167024 | Ruby | bobbyjam99-zz/metaprogramming_ruby | /lib/blocks/basics.rb | UTF-8 | 88 | 3.40625 | 3 | [] | no_license | def a_methods(a, b)
a + yield(a, b)
end
p a_methods(1, 2) {|x, y| (x + y) * 3} # =>10 | true |
a86cb5ee1ca42ffa29c69f9a25919b95d61f1769 | Ruby | pseudopeach/ttt | /ttt.rb | UTF-8 | 1,229 | 4.125 | 4 | [] | no_license | require './ttt_ai.rb'
require './ttt_game.rb'
require './ttt_human.rb'
def game_loop
begin
puts ""
puts "Would you like to go first? (y/n)"
ans = gets.chomp!.downcase
if ans == "y"
play_game(true)
elsif ans == "n"
play_game(false)
else
puts "Please answer with either 'y' or ... | true |
865ab71e98f16dacf546eb370fd4dfb6b6bc3cf8 | Ruby | annc35/S2_J2_RubyInit | /exo_13.rb | UTF-8 | 174 | 3.265625 | 3 | [] | no_license | puts "Quelle est ton année de naissance ?"
print "> "
date_of_birth = gets.chomp.to_i
i = date_of_birth
years = 2020 - date_of_birth
years.times do
puts i = i + 1
end | true |
2eaf74523ce18f2f883ed8d8aef12ceeb177877e | Ruby | Holek/hcking | /lib/tasks/venue_transit.rake | UTF-8 | 3,096 | 2.78125 | 3 | [
"MIT"
] | permissive | desc "Exports the event/single_event venue contents into venue db."
task :export_Events => :environment do
@events = Event.find(:all)
@events.each do |event|
if event.location.blank? || Venue.where(location: event.location) == []
@venue = Venue.create(
location: event.location.blank? ... | true |
4cdd9f58e8a9669c47d503d3918f51d7f7dac868 | Ruby | sepuckett86/aimee-be | /test/models/user_test.rb | UTF-8 | 1,101 | 2.640625 | 3 | [] | no_license | require 'test_helper'
class UserTest < ActiveSupport::TestCase
test 'user with a valid email should be valid' do
user = User.new(email: 'test@test.org', password: 'test')
assert user.valid?
end
test 'user with email lacking period should be invalid' do
user = User.new(email: 'test@test', password: '... | true |
cb831138b1c1c635b48c453095ef0c4b437f4f90 | Ruby | sul-dlss/cocina-models | /lib/cocina/generator/vocab.rb | UTF-8 | 2,413 | 2.734375 | 3 | [] | no_license | # frozen_string_literal: true
module Cocina
module Generator
# Class for generating a vocab
class Vocab
CLASS_COMMENT = {
'ObjectType' => 'This vocabulary defines the top level object type',
'FileSetType' => 'This vocabulary defines the types of file sets'
}.freeze
def self... | true |
90eb880e1040c20e3d29cb6669174ae6cc8e39cb | Ruby | emanuelegorga/chitter-challenge | /app.rb | UTF-8 | 2,172 | 2.546875 | 3 | [] | no_license | require 'sinatra/base'
require './lib/user'
require './lib/peep'
require './config/data_mapper'
require 'pry'
require 'mail'
require 'dotenv/load'
class Chitter < Sinatra::Base
ENV['RACK_ENV'] ||= 'development'
enable :sessions
enable :method_override
get '/' do
@peep = Peep.all
erb :index
end
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.