Skip to content

Instantly share code, notes, and snippets.

View korabh's full-sized avatar
🇽🇰

Korab Hoxha korabh

🇽🇰
View GitHub Profile
@korabh
korabh / hash_builder.rb
Last active September 14, 2020 19:34 — forked from nileshtrivedi/hash_builder.rb
HashBuilder allows you to build a Hash in Ruby similar to Builder with some enhancements
# 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
# 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
#