This file contains 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 | |
attr_reader :some_attribute | |
alias :some_attribute? :some_attribute | |
end |
This file contains 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 some_attribute | |
@some_attribute | |
end | |
# vs | |
attr_reader :some_attribute |
This file contains 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 'benchmark' | |
def fib n | |
a = 0 | |
b = 1 | |
n.times { a, b = b, a + b} | |
a | |
end | |
Benchmark.bm(10) do |x| |
This file contains 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 'benchmark' | |
def fib n | |
a = 0 | |
b = 1 | |
n.times { a, b = b, a + b} | |
a | |
end | |
Benchmark.bm(7) do |x| |
This file contains 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 'benchmark' | |
def fib n | |
a = 0 | |
b = 1 | |
n.times { a, b = b, a + b} | |
a | |
end | |
Benchmark.bm(7) do |x| |
This file contains 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
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
def method_missing(name, *args) | |
if sym.to_s =~ /^play_(\w+)$/ | |
system("open songs/#{$1}.m4a") | |
else | |
# Here, very important! |
This file contains 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
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
def method_missing(name, *args) | |
if sym.to_s =~ /^play_(\w+)$/ | |
system("open songs/#{$1}.m4a") | |
else | |
# Here, very important! |
This file contains 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
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
module GreyMagic | |
def method_missing(name, *args) | |
if sym.to_s =~ /^play_(\w+)$/ | |
system("open songs/#{$1}.m4a") | |
else |
This file contains 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
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
# Make an alias of the previous method_missing definition | |
alias method_missing_without_show method_missing | |
def method_missing(name, *args, &block) | |
if sym.to_s =~ /^play_(\w+)$/ |
This file contains 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
# This snippet is taken from: | |
# "The Polite Programmer's Guide to Ruby Etiquette" | |
# http://bit.ly/hrwdPY | |
class BlackMagicStereo < Stereo | |
def method_missing(name, *args) | |
if sym.to_s =~ /^play_(\w+)$/ | |
system("open songs/#{$1}.m4a") | |
else | |
# Here, very important! |