Skip to content

Instantly share code, notes, and snippets.

@Antiarchitect
Created November 7, 2010 14:04
Show Gist options
  • Save Antiarchitect/666139 to your computer and use it in GitHub Desktop.
Save Antiarchitect/666139 to your computer and use it in GitHub Desktop.
Alternative way of method factory
Financing::FINANCINGS.each do |method|
define_method method do
if current_period && current_period != :nil
instance_variable_defined?("@#{method}") ? nil : instance_variable_set("@#{method}", Hash.new)
instance_variable_get("@#{method}")[current_period.id] ||= current_period.method("#{method}").call
else
0.0
end
end
end
Financing::FINANCINGS.each do |method|
define_method method do
if current_period && current_period != :nil
instance_variable_defined?("@#{method}") ? nil : instance_variable_set("@#{method}", Hash.new)
instance_variable_get("@#{method}")[current_period.id] ||= current_period.send(method)
else
0.0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment