Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] pervasives-1.1.0

Reply
Thread Tools

[ANN] pervasives-1.1.0

 
 
ara.t.howard
Guest
Posts: n/a
 
      09-25-2007


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://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/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




 
Reply With Quote
 
 
 
 
Robert Dober
Guest
Posts: n/a
 
      09-25-2007
On 9/25/07, ara.t.howard <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments