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 Person | |
attr_accessor :name | |
def method_missing(method_name, *args, &block) | |
if method_name == :email | |
"[email protected]" | |
else | |
"Hey, you just called the #{method_name} method / | |
With these arguments: #{args.join(' ')} / | |
But there is no such method" |
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 Tree | |
# Pretend this is a real implementation | |
def find_node(conditions = {}) | |
"find the node by #{conditions.inspect}" | |
end | |
def method_missing(method_name, *arguments, &block) | |
return super unless method_name.to_s =~ /^find_node_by_(.*)$/ | |
find_node($1.to_sym => arguments.first) | |
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
class Person | |
def method_missing(m, *args, &block) | |
puts "Method Missing: Called #{m} with #{args.inspect} and #{block}" | |
end | |
def hello | |
puts "Hello from class Person" | |
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
class Student | |
def law_fees | |
21000 | |
end | |
def physical_science_fees | |
22000 | |
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
class Student | |
# ommitted | |
def fees(school) | |
send("#{school}_fees") | |
end | |
def method_missing(method_name) | |
return super unless /^.+_fees$/ =~ method_name | |
20000 | |
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
Rails.application.routes.draw do | |
root 'home#index' | |
resources :events, only: [:index, :show] | |
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
namespace :fake do | |
desc "Generate Fake Data | |
task :data => :environment do | |
generate_fake | |
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
class CreateUsers < ActiveRecord::Migration | |
def change | |
create_table :users do |t| | |
t.string :first_name | |
t.string :last_name | |
t.string :email | |
t.timestamps null: false | |
end | |
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
class Person < ActiveRecord::Base | |
validates :email_confirmation, presence: true | |
validates :name, length: { minimum: 2 } | |
validates :bio, length: { maximum: 1000, | |
too_long: "%{count} characters is the maximum allowed" } | |
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 Array do | |
describe "includes_subset?" do | |
it "finds subsets" do | |
a = [1,2,3,4,5] | |
b = [1,2] | |
expect(a.includes_subset?(b)).to eq(true) | |
end | |
end | |
end |