Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Bennett-Lovesey undecided

View GitHub Profile
View magical_mr_mistoffelees.rb
# Premise: a chainable DSL where evaluating a section in an if statement calls valid?
# Example: Each item changes the current synonym, it tests it against
class Moggy
SYNONYMS = [:cat, :moggy, :pussycat, :feline]
def set(syn)
@synonym = syn
self
end
@undecided
undecided / not_matches_vs_does_not_match.rb
Created Aug 28, 2012
Another ruby funny that caught me out... Want to guess what these should output?
View not_matches_vs_does_not_match.rb
"fish" =~ /ish/
"fish" !=~ /ish/
!("fish" =~ /ish/) # equivalent to "fish" !~ /ish/ - thanks @MrJaba and @kerryb!
@undecided
undecided / implicit_returns_with_ensure.rb
Created Aug 24, 2012
I got caught out by this. Anyone want to guess which string gets returned by this method?
View implicit_returns_with_ensure.rb
def foo
raise "I iz a fool"
"But you don't know, man"
rescue Exception => e
"I caught your foolness"
ensure
"and I returned you a fish"
end
@undecided
undecided / ruby_and_mirah.rb
Created Mar 9, 2011
Shows a simple class implemented in Ruby and Mirah
View ruby_and_mirah.rb
# Ruby
class Rubyish
def a_method(some_string, some_hash)
@message = some_string
@transform = some_hash
puts @message
end
def another_method
@transform.each_pair do |key, val|
You can’t perform that action at this time.