Show
Ignore:
Timestamp:
06/06/08 02:05:18 (5 years ago)
Author:
ujihisa
Message:

lang/ruby/misc/yhara/yhara.rb: fix bug

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/misc/yhara/yhara.rb

    r13313 r13314  
    11class << (Alex = Class.new) 
    2   %w[_ ____].each {|word| define_method(word) { Yhara.new(self).send(word) } } 
     2  %w[_ ____].map {|w| define_method(w) { Yhara.new(self).send(w) } } 
    33end 
    44 
    55class Yhara 
    66  def initialize(who) 
    7     @who = who 
    8     @queue = [] 
     7    @who = who; @queue = [] 
    98  end 
    109 
    11   %w[y hara].each do |word| 
    12     ['', '?', '!'].each do |suffix| 
    13       define_method('_' * word.size + suffix) { 
    14         @queue << word 
    15         self 
    16       } 
     10  %w[y hara].map do |w| 
     11    ['', '?', '!'].map do |s| 
     12      define_method('_' * w.size + s) { @queue << w; self } 
    1713    end 
    1814  end 
    1915 
    2016  def to_s 
    21     # TODO: use @who 
    22     system 'say', @queue.join(' ') 
     17    tmp = @queue.join(' ') 
     18    system 'say', tmp 
     19    @queue = [] 
     20    "#{@who}: #{tmp}" 
    2321  end 
    2422  alias inspect to_s 
     
    2725if $0 == __FILE__ 
    2826  code = 'Alex.____._._.____?' 
    29   puts code 
    30   eval code 
     27  eval "p #{code}" 
    3128end