Skip to content

Instantly share code, notes, and snippets.

@p886
Last active August 29, 2015 14:03
Show Gist options
  • Save p886/a128d93ad524b7bce378 to your computer and use it in GitHub Desktop.
Save p886/a128d93ad524b7bce378 to your computer and use it in GitHub Desktop.
Anonymous Class for quickly building Fake Objects
# 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