how to use ruby methods in Vagrantfiles?

10 views
Skip to first unread message

Maurizio Vitale

unread,
Sep 13, 2016, 1:07:50 AM9/13/16
to vagra...@googlegroups.com
I don't know the first thing about ruby, but I'd like to transform values in a hash.

The following works in pure ruby:

def replace(hash)
  hash.inject({}) do |h,(k,v)|
    if v.kind_of? String
      h[k] = v.upcase
    elsif v.kind_of? Fixnum
      h[k] = v
    else
      h[k] = replace(v)
    end
    h
  end      
end

but when I try to use it inside a Vagrantfile, I get errors about inject being undefined:

/home/mav/Workspaces/i2/new/vagrant_functions/utility.rb:141:in `replace': undefined method `inject' for nil:NilClass (NoMethodError)

is there any documentation on how to use ruby in vagrantfiles?

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages