Remove_const does not play nice with require

$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

Step 1

···

==========
irb(main):002:0> require 'ostruct'
=> true

Step 2

irb(main):005:0* Object.send(:remove_const, :OpenStruct)
=> OpenStruct

Step 3

# ensure that OpenStruct is truly removed
irb(main):006:0> Object.send(:remove_const, :OpenStruct)
NameError: constant Object::OpenStruct not defined
        from (irb):6:in `remove_const'
        from (irb):6:in `send'
        from (irb):6

Step 4

irb(main):007:0> require 'ostruct'
=> false

Step 5

irb(main):009:0> OpenStruct.new
NameError: uninitialized constant OpenStruct
        from (irb):9

Questions:

1) OpenStuct constant was removed in step2. Why the return value of
require in step 4 is "false" ?

2) require was done in step 4 then why OpenStruct is not available and
why did step 5 fail ?
--
Posted via http://www.ruby-forum.com/.

1) OpenStuct constant was removed in step2. Why the return value of
require in step 4 is "false" ?

`require` consults $LOADED_FEATURES.

2) require was done in step 4 then why OpenStruct is not available and
why did step 5 fail ?

Because "ostruct" is already on $LOADED_FEATURES.

~ j.

···

On May 12, 2010, at 1:31 PM, Raj Singh wrote: