HomePhorge

`instance_variables` changes return type between 1.8 and 1.9
1f4e44c26a0dUnpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

instance_variables changes return type between 1.8 and 1.9

The return type of instance_variables changes between Ruby 1.8 and 1.9
releases; it used to return an array of strings in the form "@foo", but
now returns an array of symbols in the form :@foo.

Nothing else in the stack cares which form you get - you can pass the
string or symbol to things like instance_variable_set and they will work
transparently.

Having the same form in all releases of Puppet is a win, though, so we
pick a unification and enforce than on all releases. That way developers
who do set math on them (eg: for YAML rendering) don't have to handle the
distinction themselves.

In the sane tradition, we bring older releases into conformance with newer
releases, so we return symbols rather than strings, to be more like the
future versions of Ruby are.

We also carefully support reloading, by only wrapping when we don't
already have the original version of the method aliased away somewhere.

This includes a second monkey-patch, on the resolv library that ships with
Ruby 1.8. This is the only bit of code in the core stack that made
assumptions about the return format of names from instance_methods.

Specifically, it assumed they were strings, and could be evaluated using
instance_eval to fetch out the value. The fix is to replace that with a
call to instance_variable_get which, like it does in Ruby 1.9, avoids the
cost of eval parsing as well as being more robust overall.

I did audit the rest of the standard library on 1.8.5 and 1.8.7 to verify
this. We only need worry if we start using the SOAP or Tk support.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>

Details

Provenance
Daniel Pittman <daniel@puppetlabs.com>Authored on
vanmeeuwenPushed on Jun 2 2015, 2:22 PM
Parents
rPU769eb943bda6: Eliminate dead home-made assertion-at-dev-time-only code.
Branches
Unknown
Tags
Unknown

Event Timeline

Daniel Pittman <daniel@puppetlabs.com> committed rPU1f4e44c26a0d: `instance_variables` changes return type between 1.8 and 1.9 (authored by Daniel Pittman <daniel@puppetlabs.com>).Mar 30 2012, 9:15 PM