This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def initialize | |
singleton_class.class_eval { def foo; :bar; end } | |
singleton_class.class_eval do | |
alias_method :f_o_o, :foo | |
end if respond_to? :foo | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe '#reload' do | |
# Attributes | |
let(:id) { 25 } | |
let(:name) { 'Pikachu' } | |
let(:new_name) { 'Pika' } | |
let(:pokemon) { Pokemon.find(id) } | |
it 'returns an object with the original attributes' do | |
pokemon.name = new_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo | |
13 | |
end | |
2.times do | |
p foo | |
foo = 'something else' | |
p foo | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'gosu' | |
def linear_map(value, mina, maxa, minb, maxb) | |
(maxb - minb) * (value - mina) / (maxa - mina) + minb | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tempfile' | |
module Music | |
refine Float do | |
def hz | |
self | |
end | |
def khz | |
self * 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/autorun' | |
RSpec::Matchers.define :be_one_of do |expected| | |
match do |actual| | |
expected.include? actual | |
end | |
end | |
RSpec.describe 13 do | |
it 'is in the list of allowed values' do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/autorun' | |
class X | |
def call | |
fund_query | |
end | |
private | |
def fund_qeuery |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_model' | |
class X | |
include ActiveModel::Validations | |
include ActiveModel::Attributes | |
attribute :blah | |
validates :blah, numericality: { greater_than_or_equal_to: 0 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_model' | |
class Form | |
include ActiveModel::Validations | |
include ActiveModel::Attributes | |
attribute :blah | |
validates :blah, numericality: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'forwardable' | |
# Board is a 9x9 standard sudoku board. This class does not care about what is | |
# stored in each cell of the board, it merely provides indexing and enumeration | |
# methods including accessing rows, columns, or 3x3 sudoku boxes. | |
class Board | |
extend Forwardable | |
# @param data [Array] flat array of 81 initial cell values | |
def initialize(data) |
NewerOlder