[ANN] pervasives-1.1.0

Discussion in 'Ruby' started by ara.t.howard, Sep 25, 2007.

  1. ara.t.howard

    ara.t.howard Guest

    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
     
    ara.t.howard, Sep 25, 2007
    #1
    1. Advertising

  2. ara.t.howard

    Robert Dober Guest

    On 9/25/07, ara.t.howard <> 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
     
    Robert Dober, Sep 25, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Sampson [MSFT]

    [ANN]: NNTP Server slow downs.

    Mike Sampson [MSFT], Oct 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    Mike Sampson [MSFT]
    Oct 7, 2003
  2. Mike Sampson [MSFT]

    [ANN]: NNTP Server slow downs.

    Mike Sampson [MSFT], Dec 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    502
    Mike Sampson [MSFT]
    Dec 6, 2003
  3. Richard Grimes [MVP]

    ANN: Free .NET Workshops

    Richard Grimes [MVP], Jul 4, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    506
    Richard Grimes [MVP]
    Jul 4, 2005
  4. Michael Livsey
    Replies:
    3
    Views:
    429
    Michael Livsey
    May 27, 2004
  5. Replies:
    6
    Views:
    117
    Trans
    Jan 6, 2007
Loading...

Share This Page