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
# Allows you to build a Hash in a fashion very similar to Builder. Example: | |
# | |
# HashBuilder.build! do |h| | |
# h.name "Brent" | |
# h.skillz true | |
# h.location do | |
# h.planet "Earth" | |
# end | |
# end | |
# |
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
# Allows you to build a Hash in a fashion very similar to Builder. Example: | |
# Fork of https://gist.github.com/360506 by BrentD with some enhancements | |
class HashBuilder | |
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|^object_id$)/ } | |
def initialize | |
@hash = Hash.new | |
@target = @hash | |
end |