Skip to content

Instantly share code, notes, and snippets.

View undecided's full-sized avatar

Matthew Bennett-Lovesey undecided

View GitHub Profile
@undecided
undecided / magical_mr_mistoffelees.rb
Created August 31, 2012 10:36
How do I do this?
# 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 August 28, 2012 13:59
Another ruby funny that caught me out... Want to guess what these should output?
"fish" =~ /ish/
"fish" !=~ /ish/
!("fish" =~ /ish/) # equivalent to "fish" !~ /ish/ - thanks @MrJaba and @kerryb!
@undecided
undecided / implicit_returns_with_ensure.rb
Created August 24, 2012 09:12
I got caught out by this. Anyone want to guess which string gets returned by this method?
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 March 9, 2011 22:32
Shows a simple class implemented in Ruby and Mirah
# 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|