Anomaly in first example of Needles, an Aspect-Oriented Programming tool

R

Richard

Hi All,

I intend to use Needle in my future Ruby and RoR development, so I
want to got through it tutorial at
http://needle.rubyforge.org/chapter-1.html in detail.

Following is a test of the first example. It works great except for
one anomaly: There is an output line with "nil" between the two debug
line surround the "real" body of the method. What could be the cause
of it?

Thanks in advance,
Richard

========= Test.rb ==========
# http://needle.rubyforge.org/chapter-1.html
# Log method without 'Nails'
# Class Logger: http://www.ruby-doc.org/core/classes/Logger.html

require "logger.rb" # (In
K:\_Utilities\Ruby_1.8.2-15\ruby\lib\ruby\1.8)

def foo( arg1, arg2 )
@log = Logger.new(STDOUT)
@log.level = Logger::DEBUG
@log.debug("Created logger")

@log.debug( "in foo with #{arg1} and #{arg2}" ) if @log.debug?
result = arg1 + arg2 # The "real" body of the method "foo"
@log.debug( "finishing foo with #{result}" ) if @log.debug

return result

rescue Exception => e
@log.debug( "foo raised exception #{e.message} (#{e.class})" ) if
@log.debug?
raise
end

foo(1,2)

===== Output =======
D, [2006-11-30T22:46:41.609000 #280] DEBUG -- : Created logger
D, [2006-11-30T22:46:41.609000 #280] DEBUG -- : in foo with 1 and 2
D, [2006-11-30T22:46:41.609000 #280] DEBUG -- : nil
D, [2006-11-30T22:46:41.609000 #280] DEBUG -- : finishing foo with 3
 
J

Joseph Taylor

@log.debug( "finishing foo with #{result}" ) if @log.debug

You forgot a question mark.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top