# Pervasives-0.0.1

**URL:** <https://www.ruby-forum.com/t/pervasives-0-0-1/81269>\
**Category:** Ruby\
**Created:** [January 6, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269 "2007-01-06T19:30:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 6, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/1 "2007-01-06T19:30:51Z")

</div>

NAME

pervasives.rb

SYNOPSIS

access to pristine object state. if you don’t metaprogram you  
probably  
don’t need it

INSTALL

gem install pervasives

URIS

[http://rubyforge.org/projects/codeforpeople/](http://rubyforge.org/projects/codeforpeople/)  
[http://codeforpeople.com/lib/ruby](http://codeforpeople.com/lib/ruby)

SAMPLES

\<========\< samples/a.rb \>========\>

~ \> cat samples/a.rb

```
 #
 # Pervasives allows objects' method to be accessed in a pristine 

```

state, even  
# when some effort has been made to derride them  
#  
require ‘pervasives’

```
   class OpenStruct
     instance_methods.each{|m| undef_method m unless m[%r/__/]}

     def initialize
       @table = {}
     end

     def method_missing m, *a, &b
       case m.to_s
         when %r/[=]$/
           @table[m.to_s.delete('=')] = a.shift
         when %r/[?!]$/
           !!@table[m.to_s.delete('?!')]
         else
           @table[m.to_s]
       end
     end

     def inspect
       @table.inspect
     end
   end

   os = OpenStruct.new

   os.object_id = 42
   os.send = 42
   os.instance_eval = 42

   p os

   p os.object_id
   p Pervasives.object_id(os)

   p os.send
   p Pervasives.send(os, "key=", "value")

   p os.instance_eval
   p Pervasives.instance_eval(os){ @table }

```

~ \> ruby samples/a.rb

```
 {"instance_eval"=>42, "send"=>42, "object_id"=>42}
 42
 -609487514
 42
 "value"
 42
 {"instance_eval"=>42, "send"=>42, "key"=>"value", "object_id"=>42}

```

\<========\< samples/b.rb \>========\>

~ \> cat samples/b.rb

```
 #
 # sometimes it may be more convenient to use a Pervasives::Proxy 

```

object  
# insteand of using Pervasives directly  
#  
require ‘pervasives’

```
   class BlankSlate
     instance_methods.each { |m| undef_method m unless m =~ /^__/ }

     def object_id() 42 end
   end

   bs = BlankSlate.new

   proxy = Pervasives::Proxy.new bs

   p bs.object_id
   p proxy.object_id

```

~ \> ruby samples/b.rb

```
 42
 -609489100

```

\<========\< samples/c.rb \>========\>

~ \> cat samples/c.rb

```
 #
 # the special '__' method accesses an object's Pervasives::Proxy
 #
   require 'pervasives'

   class BlankSlate
     instance_methods.each { |m| undef_method m unless m =~ /^__/ }
     def object_id() 42 end
   end

   bs = BlankSlate.new

   p bs.object_id
   p __(bs){ object_id }

```

~ \> ruby samples/c.rb

```
 42
 -609486982

```

\<========\< samples/d.rb \>========\>

~ \> cat samples/d.rb

```
 #
 # it all works for classes too
 #
   require 'pervasives'

   class C
     def self.new() raise end
     def inspect() 42 end
   end

   p( Pervasives.new(C) )
   p( Pervasives::Proxy.new(C).new )
   p( __(C).new )

```

~ \> ruby samples/d.rb

```
 42
 42
 42

```

enjoy and send in yer comments/patches!

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 6, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/2 "2007-01-06T22:22:20Z")

</div>

removed\_email\_address@domain.invalid wrote:

> enjoy and send in yer comments/patches!

is this perhaps impossible b/c of callbacks? since any dot magic DSL is  
created via method\_missing how can we possibley remove all the methods  
including #method\_missing? and if we’re stuck with one exception, what  
does a half-dozen more really make (just so long as they have uncommon  
names)?

t.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/3 "2007-01-19T16:30:38Z")

</div>

removed\_email\_address@domain.invalid wrote:

> enjoy and send in yer comments/patches!

```
_ = Pervasives

_.send(obj, message)

```

T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/4 "2007-01-19T16:31:36Z")

</div>

On 1/6/07, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> removed\_email\_address@domain.invalid wrote:
> 
> > enjoy and send in yer comments/patches!
> 
> ```
> _ = Pervasives
> 
> _.send(obj, message)
> 
> ```

Ooh. I think that at least in the context of this lib, that’s  
reasonable enough.

Surely concise

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 25, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/5 "2007-09-25T22:34:15Z")

</div>

On Sat, 6 Jan 2007, Trans wrote:

> removed\_email\_address@domain.invalid wrote:
> 
> > enjoy and send in yer comments/patches!
> 
> \_ = Pervasives
> 
> \_.send(obj, message)

yeah - i thought about that, but i use ‘\_’ often in loops like

hash.map{|k,\_| k.upcase}

when i plan to ignore a block param.

cheers.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [September 25, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/6 "2007-09-25T22:52:36Z")

</div>

On 1/6/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> yeah - i thought about that, but i use ‘\_’ often in loops like
> 
> hash.map{|k,\_| k.upcase}
> 
> when i plan to ignore a block param.

Hmm, also a good tip Ara, neat.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/pervasives-0-0-1/81269/7 "2007-01-19T16:31:23Z")

</div>

removed\_email\_address@domain.invalid wrote:

> NAME
> 
> pervasives.rb
> 
> SYNOPSIS
> 
> access to pristine object state. if you don’t metaprogram you probably  
> don’t need it  
> [snip]  
> enjoy and send in yer comments/patches!

well, of course i think it’s great that you took the time to do this.  
but i’m afraid i have an unfortunate little story to tell you.

you see about a year ago i was working on my BasicObject implementation  
and how to deal with this exact problem. if you recall i brought up  
this very thing on ruby-talk. i had implemented my own version of  
Pervasives – i beleive it was call Meta and/or Inspect at first, but i  
later realized the methods fit well in ObjectSpace. tied to this I  
created a shortcut to these mthod via a proxy like yours but rather  
than ‘**(obj).foo’, mine was 'obj.**.foo.’. Hey, great mind think  
alike! 🙂

now the tragic ending… with my new lib in hand i went about reworking  
my meta code with it. well, it wasnt too long after that i realized it  
sucked. my meta-code become bloated, harder to read and slower – it  
just wasn’t worth it. and so i gave up on it.

so that’ my little story and i fear the same will happen for you. i  
think if the issue is going to be truly addressed, we need to work on  
something more fundamental. btw eventually i just settled on using  
object\_class and object\_send aliases when need be (shadow methods  
**class** , **send** , etc. just got on my nerves) and lived with the  
over-ride imperfections.

T.
