Forum: Ruby Solution: metakoans.rb

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wilson B. (Guest)
on 2006-02-19 16:07
(Received via mailing list)
Great quiz. Thanks for writing it.  Sorry to post this after exactly
48 hours, but I have to start a road trip in about 10 minutes, and
wanted to get this out first.

I managed to get the code down to 15 lines without semicolons or
anything particularly in need of wrapping.  However, 42 seemed like
such a good number that I padded my solution out with poems by Ikkyu.

I couldn't quite wrap my head around a solution that avoided the
string form of class_eval, but hopefully someone managed it.

# so many paths go up from the foothills
# but one moon grazes the peak

# stare at it until your eyes drop out
# this desk this wall this unreal page

# the edges of the sword are life and death
# no one knows which is which

# inside the koan clear mind
# gashes the great darkness

class Module
  def attribute(name, &block)
    return {|k,v| attribute(k) {v}} if name.is_a?(Hash)
    define_method("__#{name}__", block || proc{nil})
    class_eval <<-ZEN
      attr_writer :#{name}
      def #{name}
        defined?(@#{name}) ? @#{name} : @#{name} = __#{name}__
      def #{name}?
        true unless #{name}.nil?

# clouds endless clouds climbing beyond
# ask nothing from words on a page

# lone moon, no clouds
# we stumble through the night

# long life
# the wild pines want it too

# mirror facing a mirror
# nowhere else

# only one koan matters
# you
This topic is locked and can not be replied to.