RubyInline Errors (Calling Static Inline Methods?)
I'm trying to learn Ruby from a book. Unfortunately, I'm having alot of trouble with Rubyline. The book provides the following code:
Code:
require 'rubygems'
require 'inline'
require 'benchmark'
class CFactorial
class << self
inline do |builder|
builder.c %q{
long factorial(int value){
long result = 1, i = 1;
for(i = 1; i <= value; ++i)
result *= i;
return result;
}
}
end
end
end
Trying to call factorial via:
Code:
puts CFactorial.factorial(8)
yields the error message:
Code:
/usr/local/lib/ruby/gems/1.9.1/gems/RubyInline-3.8.1/lib/inline.rb:365:in `module_name': undefined method `gsub' for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/gems/1.9.1/gems/RubyInline-3.8.1/lib/inline.rb:375:in `so_name'
from /usr/local/lib/ruby/gems/1.9.1/gems/RubyInline-3.8.1/lib/inline.rb:498:in `load_cache'
from /usr/local/lib/ruby/gems/1.9.1/gems/RubyInline-3.8.1/lib/inline.rb:818:in `inline'
from /home/craig/ruby/inline.rb:8:in `singletonclass'
from /home/craig/ruby/inline.rb:7:in `<class:CFactorial>'
from /home/craig/ruby/inline.rb:6:in `<main>'
Removing the class << self (which is not explained), but appears to designate a block of code that is static, allows the inline code to work via an instantiated object. But I'd like the inline code to be static to the class. Does anyone know what the problem is?