Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created September 26, 2008 12:12
Show Gist options
  • Select an option

  • Save dchelimsky/13087 to your computer and use it in GitHub Desktop.

Select an option

Save dchelimsky/13087 to your computer and use it in GitHub Desktop.
module InstanceVariableHelpers
def set_ivar(type, name, obj)
instance_variable_set ivar_name(type, name), obj
end
def get_ivar(type, name)
returning instance_variable_get(ivar_name(type, name)) do |obj|
yield obj if block_given?
end
end
private
def ivar_name(type, name)
"@#{type}_#{name.gsub(/[ -]/,'_').gsub('&','and')}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment