# Anomaly in first example of Needles, an Aspect-Oriented Prog

**URL:** <https://www.ruby-forum.com/t/anomaly-in-first-example-of-needles-an-aspect-oriented-prog/77873>\
**Category:** Ruby\
**Created:** [December 1, 2006, 4:50am UTC](https://www.ruby-forum.com/t/anomaly-in-first-example-of-needles-an-aspect-oriented-prog/77873 "2006-12-01T04:50:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 1, 2006, 4:50am UTC](https://www.ruby-forum.com/t/anomaly-in-first-example-of-needles-an-aspect-oriented-prog/77873/1 "2006-12-01T04:50:39Z")

</div>

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](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](http://needle.rubyforge.org/chapter-1.html)

# Log method without ‘Nails’

# Class Logger: [http://www.ruby-doc.org/core/classes/Logger.html](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

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 1, 2006, 11:51am UTC](https://www.ruby-forum.com/t/anomaly-in-first-example-of-needles-an-aspect-oriented-prog/77873/2 "2006-12-01T11:51:25Z")

</div>

> @log.debug( “finishing foo with #{result}” ) if @log.debug

You forgot a question mark.

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [December 1, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/anomaly-in-first-example-of-needles-an-aspect-oriented-prog/77873/3 "2006-12-01T17:30:42Z")

</div>

Hi Joseph,

Thank you very much!

Best wishes,  
Richard
