Last active
August 29, 2015 14:03
-
-
Save p886/a128d93ad524b7bce378 to your computer and use it in GitHub Desktop.
Anonymous Class for quickly building Fake Objects
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
# Anonymous Class for quickly building Fake Objects | |
# advantage over Struct: doesn't even need a single argument | |
# (Struct.new accepts 1+ arguments, this 0) | |
thing = Class.new do | |
def name | |
"helloooo!!" | |
end | |
end.new # <-- immediately creating an instance of the anoymous class | |
p thing # => #<#<Class:0x007fe66c05e178>:0x007fe66c05e0d8> | |
puts thing.name # => helloooo!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment