class Modernize::StructContext
This class is used to make the context key/values available as instance variables to the map methods.
Public Class Methods
new(context, hash)
click to toggle source
# File lib/modernizer.rb, line 94 def initialize(context, hash) create_getter(:hash, hash) context.each do |key, value| create_getter(key, value) end end
Public Instance Methods
create_getter(name, value)
click to toggle source
Creates getters for each instance variable and sets the initial value.
# File lib/modernizer.rb, line 110 def create_getter(name, value) instance_variable_set(:"@#{name}", value) create_method(name.to_sym) do instance_variable_get(:"@#{name}") end end
create_method(name, &block)
click to toggle source
Helper method which wraps define_method.
# File lib/modernizer.rb, line 103 def create_method(name, &block) self.class.send(:define_method, name, &block) end