Ruby动态生成字符串..然后评估该字符串

时间:2011-05-27 03:42:42

标签: ruby nokogiri

以下是设置:

xml.search返回一个节点集(多个值),我循环使用.each do |l|

langHash = hash with lots of 2 lette language codes 'en', 'fr' etc..

我想做的就是让XXXXXXXXXXXX评价为'英语','法语'

但是当我放置时:

xml.search('Language').each do |l|
  code = "#{l.xpath('LanguageCode')}"      # => 'en', 'fr'  etc..
  language = langHash[code.to_sym]
  raise language.to_s                     # => 'English', 'French'
  this_e=seeker.experiences.build(
    :title        => XXXXXXXXXXXX,
    :of_type      => 'skill'
  )
  this_e.save
  this_e.shards.build(
    :description => "#{l.children.first.attr('description')}: #{l.children.text}; last used: #{l.attr('lastUsed')}",
    :experience_type => 'skill'
  ).save!
end

XXXXXXXXXX的值我试过了:

"#{language}"                   #  =>  interning empty string
"#{l.xpath('LanguageCode')}"    #  =>  interning empty string

我希望我能正确解释这一点。

0 个答案:

没有答案