Created
September 19, 2010 05:51
-
-
Save davelyon/586449 to your computer and use it in GitHub Desktop.
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
# More ruby fun! | |
def power(base) | |
Proc.new {|x| base ** x } | |
end | |
base2 = power(2) # => #<Proc:0x00000001001569d0@-:4> | |
base2.call(8) # => 256 | |
# Eigenclasses | |
class CrazyStuff | |
attr_reader :var # Read only! | |
def initialize | |
@var = "You can't write me" | |
end | |
private | |
def nonono() | |
return "BAD!" | |
end | |
end | |
eigen = CrazyStuff.new() | |
def eigen.var=(monkeyPatch) | |
@var = monkeyPatch | |
end | |
eigen.var="Ha!" # => "Ha!" | |
eigen.var # => "Ha!" | |
breakin = CrazyStuff.new() | |
breakin.instance_eval("@var=\"EVIL\"") # this is evil. But it works! | |
breakin.var # => "EVIL" | |
# Rubyisms... | |
def atLeastZero(someNumber) | |
[0,someNumber].max | |
end | |
atLeastZero(1) # => 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment