I want to use the erb
template feature of ruby. But I am not able to run the sample code provided.
I find that erb is installed:
# file /usr/lib/ruby/1.9.1/erb.rb
/usr/lib/ruby/1.9.1/erb.rb: ASCII English text
and it was installed along with ruby:
# dpkg -S /usr/lib/ruby/1.9.1/erb.rb
libruby1.9.1: /usr/lib/ruby/1.9.1/erb.rb
I am running below sample code which is provided in /usr/lib/ruby/1.9.1/erb.rb
#!/usr/bin/ruby
require 'erb'
x = 42
template = ERB.new <<-EOF
The value of x is: <%= x %>
EOF
puts template.result(binding)
I get below error when I run the code:
/workspace/ruby/erb.rb:4:in `<top (required)>': uninitialized constant ERB (NameError)
from /workspace/ruby/erb.rb:2:in `require'
from /workspace/ruby/erb.rb:2:in `<main>'
Question: what is missing in above code?
Here is my platform:
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 10.04.4 LTS
Release: 10.04
Codename: lucid
# uname -m
i686
and my ruby version:
# ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i486-linux]
ANSWER:
@matt's comment is answer to this question. I had named my script as erb.rb
and that was the problem. I renamed it to testing_erb.rb
and it worked. Please check matt's comment for more details.