The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Self destructing code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rodney ramdas

Posts: 66
Nickname: pinupgeek
Registered: Jun, 2006

Rodney Ramdas is a de-enterprised Ruby on Rails developer from the Netherlands.
Self destructing code Posted: Aug 2, 2006 6:25 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rodney ramdas.
Original Post: Self destructing code
Feed Title: pinupgeek.com
Feed URL: http://feeds.feedburner.com/pinupgeek
Feed Description: A personal take on Ruby and Rails
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rodney ramdas
Latest Posts From pinupgeek.com

Advertisement

So _why wrote:

class Trial
    def run_me
       def self.run_me; raise Exception, "NO MORE." end
       puts "Your trial period has ended." 
    end
 end

So you can have your code self-destruct:

 t = Trial.new
 t.run_me
 #=> Your trial period has ended.
 t.run_me
 #=> (trial):3:in `run_me': NO MORE. (Exception)

But then Scott wrote it in Io and now I find myself here:

 Trial := Object clone do(
  runMe := method(
    self runMe = method(Exception raise("NO MORE."))
    writeln("Your trial period has ended.")     
  )
)

And that allows an Ionist to have his code clean up after itself like so:

t := Trial clone
t.runMe #=> Your trial period has ended.
t.runMe #=> Exception: NO MORE.

And then jer shows me how we can do Object#method_missing in Io:

Object clone do(
  foo := method(a, a .. " bob!")
)

B := A clone do(
  foo := method(a, resend)
)

B foo("hey")

or you could use super() which does the same thing. I thought you could do it with forward() but that’s different. Not sure how it’s different yet.

Read: Self destructing code

Topic: people are stupid Previous Topic   Next Topic Topic: What's New in Edge Rails: Restful Routes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use