lib/never_bounce/api/feature/igetset.rb
# Get/set an OTF instance variable of any type.
#
# Ruby's <tt>||=</tt> works nicely with object instances, but requires special bulky treatment for <tt>nil</tt> and <tt>false</tt>.
# For example, this will cause a hidden glitch since <tt>==</tt> can evaluate to <tt>false</tt>:
#
#   @is_verbose ||= begin
#     # This clause will be evaluated *every time* if its value is `false`.
#     ENV["VERBOSE"] == "y"
#   end
#
# There's a number of solutions to this problem, all of which involve calling <tt>instance_variable_*</tt> a few times per attribute accessor.
#
# <tt>igetset</tt> does this job for you. All you have to do is specify a block to compute the value.
#
#   igetset(:is_verbose) { ENV["VERBOSE"] == "y" }
#
# See source for details.
Get/set an OTF instance variable of any type.
Ruby's ||= works nicely with object instances, but requires special bulky treatment for nil and false.
For example, this will cause a hidden glitch since == can evaluate to false.

@is_verbose ||= begin
This clause will be evaluated *every time* if its value is `false`.

There's a number of solutions to this problem, all of which involve calling instance_variable_* a few times per attribute accessor.

igetset does this job for you. All you have to do is specify a block to compute the value.



See source for details.
Get / set an OTF instance variable of any type . Ruby ' s || = works nicely with object instances but requires special bulky treatment for nil and false . For example this will cause a hidden glitch since == can evaluate to false . @is_verbose || = begin This clause will be evaluated * every time * if its value is ` false ` . There ' s a number of solutions to this problem all of which involve calling instance_variable_ * a few times per attribute accessor . igetset does this job for you . All you have to do is specify a block to compute the value . See source for details .
def igetset(name, &compute)
        if instance_variable_defined?(k = "@#{name}")
          instance_variable_get(k)
        else
          instance_variable_set(k, compute.call)
        end
      end
def igetset ( name , & compute ) if instance_variable_defined? ( k = "@#{name}" ) instance_variable_get ( k ) else instance_variable_set ( k , compute . call ) end end
Get/set an OTF instance variable of any type.
Get / set an OTF instance variable of any type .
name
compute