Skip to content

Instantly share code, notes, and snippets.

@ggolin
Last active December 20, 2015 10:30
Show Gist options
  • Save ggolin/6115568 to your computer and use it in GitHub Desktop.
Save ggolin/6115568 to your computer and use it in GitHub Desktop.
# resources/foo.rb
attribute :x, :kind_of => String, :default => nil
# providers/foo.rb
x = new_resource.x.nil? ? new_resource.name : new_resource.x
# providers/bar.rb
foo new_resource.name do
x "foobar"
end
# x always ends up as "schlep".
@miah
Copy link

miah commented Jul 30, 2013

The ternary operator is basically doing this:

if new_resource.x.nil?
  new_resource.name
else
  new_resource.x
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment