Black magic attribute initialization.
Usage:
require 'black_magic'
class Demon
attr_init(
:name,
:source,
)
.public(:name)
.with_class_method_call(:summon)
def summon
puts "#{name} says 'bwoahahaha!'"
end
end
demon = Demon.new(name: 'Lucy', source: 'fire')
demon.name
# => "Lucy"
demon.public_methods.include?(:source)
# => false
Demon.summon(name: 'Lucy', source: 'fire')
# Lucy says 'bwoahahaha!'
# => nil
Be a rebel and run this in production or any other mission critical code. ๐