Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fujin/1332652 to your computer and use it in GitHub Desktop.
Save fujin/1332652 to your computer and use it in GitHub Desktop.
This is now throwing an error when we run chef-client -i
class Machine < Struct.new(:name,:ipaddress,:role,:env)
def print_machine_csv
name.length==0 ? printf(",") : printf("\"%s\",", name)
address.length==0 ? printf(",") : printf("\"%s\",", address)
role.length==0 ? printf(",") : printf("\"%s\",", role)
env.length==0 ? printf(",") : printf("\"%s\",", env)
printf("\n")
end
end unless defined? Machine
require 'csv'
class NewMachine
attr_accessor :name, :ipaddress, :role, :env
def initialize(name, ipaddress, role, env)
@name, @ipaddress, @role, @env = name, ipaddress, role, env
end
def to_csv
[name, ipaddress, role, env].to_csv
end
end
ruby-1.9.2-p180 :018 > NewMachine.new
ArgumentError: wrong number of arguments (0 for 4)
from (irb):10:in `initialize'
from (irb):18:in `new'
from (irb):18
from /Users/aj/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
ruby-1.9.2-p180 :019 > NewMachine.new("test", "foo", "bar", "baz")
=> #<NewMachine:0x00000100c90508 @name="test", @ipaddress="foo", @role="bar", @env="baz">
ruby-1.9.2-p180 :020 > m = NewMachine.new("test", "foo", "bar", "baz")
=> #<NewMachine:0x00000100c916d8 @name="test", @ipaddress="foo", @role="bar", @env="baz">
ruby-1.9.2-p180 :021 > m.to_csv
=> "test,foo,bar,baz\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment