[Solution][QUIZ] #67 metakoans.rb

Discussion in 'Ruby' started by Ari Brown, Oct 6, 2007.

  1. Ari Brown

    Ari Brown Guest

    Here is my solution: I got stuck on like 6, so I borrowed a line and
    a half from Adam Shelly.

    I understand it looks a lot like his code, but I swear, i only
    borrowed 12 and part of 13 from him!

    #!/usr/local/bin/ruby
    #
    # Created by me on 2007-10-05.
    # Some code (lines 12, and part of 13) borrowed from Adam Shelly
    # Copyright (c) 2007. All pwnage reserved.


    class Object
    def attribute(*vars, &b)
    vars.each do |var|
    var.each_pair{|k,v| attribute [k,v] } and next if var.is_a? Hash
    var, v = var # Idea borrowed [stolen] from Adam Shelly.
    Brilliant, I might add!
    class_eval "def #{var}; @#{var} = (defined?(@#{var}) ? @#
    {var} : #{var}_proc); end" # Set up getters
    attr_writer var.to_sym # setters
    class_eval "def #{var}?; return (self.#{var}.nil? ? false :
    true ); end" # and queries
    define_method "#{var}_proc", b || Proc.new {v}
    end
    end
    end


    Ari Brown
    --------------------------------------------|
    If you're not living on the edge,
    then you're just wasting space.
     
    Ari Brown, Oct 6, 2007
    #1
    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. email55555 email55555

    [SOLUTION] Ruby Quiz #14 LCD Numbers ( solution #2 )

    email55555 email55555, Jan 9, 2005, in forum: Ruby
    Replies:
    16
    Views:
    302
    David Tran
    Jan 10, 2005
  2. David Tran
    Replies:
    9
    Views:
    234
    David Tran
    Jan 21, 2005
  3. Luke Blanshard

    [/QUIZ] metakoans.rb (#67)

    Luke Blanshard, Feb 19, 2006, in forum: Ruby
    Replies:
    8
    Views:
    145
    George Ogata
    Feb 21, 2006
  4. Florian Groß

    [SOLUTION] metakoans.rb (#67)

    Florian Groß, Feb 19, 2006, in forum: Ruby
    Replies:
    7
    Views:
    194
    Jeremy Hinegardner
    Feb 21, 2006
  5. MenTaLguY
    Replies:
    12
    Views:
    322
    MenTaLguY
    Jun 7, 2007
Loading...

Share This Page