# Pervasives-1.1.0

**URL:** <https://www.ruby-forum.com/t/pervasives-1-1-0/115425>\
**Category:** Ruby\
**Created:** [September 25, 2007, 6:43am UTC](https://www.ruby-forum.com/t/pervasives-1-1-0/115425 "2007-09-25T06:43:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [September 25, 2007, 6:43am UTC](https://www.ruby-forum.com/t/pervasives-1-1-0/115425/1 "2007-09-25T06:43:12Z")

</div>

NAME

pervasives.rb

SYNOPSIS

access to pristine object state. if you don’t metaprogram or write  
debuggers 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)

HISTORY

1.1.0

```
 added Pervasives.call method, refactored a bit, updated samples,

```

updated  
tests for new api

1.0.0

```
 is NOT backward compatible with any other pervasives version.

```

the new  
library is **greatly** simplified

SAMPLES

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

~ \> cat samples/a.rb

```
 #
 # Pervasives allows an object's methods to be accessed in a

```

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

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

   bs = BlankSlate.new

   p Pervasives(bs).methods #=> [" __object_pervasive__",

```

“ **id** ”, “ **send** ”, “ **pervasive** ”]

```
   p Pervasives(bs).is_a?(BlankSlate) #=> true

   p Pervasives(bs).instance_eval{ @a = 42 } #=> 42

   p Pervasives(bs).instance_variables #=> ["@a"]

```

~ \> ruby samples/a.rb

```
 [" __pervasive__", " __id__", " __send__"]
 true
 42
 ["@a"]

```

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

~ \> cat samples/b.rb

```
 #
 # the special method __pervasive__ is added to all objects - it

```

can be used to  
# access the pristine state  
#  
require ‘pervasives’

```
   class C
     def instance_eval(*a, &b) raise end
   end

   c = C.new

   c. __pervasive__ (:instance_eval){ @a = 42 }

   p c.instance_variables #=> ["@a"]

```

~ \> ruby samples/b.rb

```
 ["@a"]

```

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

~ \> cat samples/c.rb

```
 #
 # even if hackery removes the __pervasive__ method you can still

```

call a  
# pristine method on an object  
#  
require ‘pervasives’

```
   class VeryBlankSlate
     instance_methods.each{ |m| undef_method m }
   end

   vbs = VeryBlankSlate.new

   begin
     vbs. __pervasive__
   rescue
     'nope not even that'
   end

   Pervasives.call(vbs, :instance_eval){ @a = 42 }

   p Pervasives.call(vbs, :instance_variables) #=> ["@a"]

```

~ \> ruby samples/c.rb

```
 samples/c.rb:8: warning: undefining ` __id__' may cause serious

```

problem  
samples/c.rb:8: warning: undefining ` **send** ’ may cause serious  
problem  
[“@a”]

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

~ \> cat samples/d.rb

```
 #
 # of course it works for classes and modules too
 #
   require 'pervasives'

   class C
     def self.new() raise end

     def inspect() 42.inspect end
   end

   c = C. __pervasive__ :new

   p c #=> 42

```

~ \> ruby samples/d.rb

```
 42

```

enjoy.

a @ [http://drawohara.com/](http://drawohara.com/)

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [September 25, 2007, 11:35am UTC](https://www.ruby-forum.com/t/pervasives-1-1-0/115425/2 "2007-09-25T11:35:42Z")

</div>

On 9/25/07, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Ara,  
does this fix the bug in prototype? It was in attributes IIRC, so I am  
not sure.  
I tried last about six weeks ago and it did not work yet.

Thx in advance.  
Robert
