Forked from josephreynolds/Broken NagiosLibraryMachine.rb
Created
November 2, 2011 02:01
-
-
Save fujin/1332652 to your computer and use it in GitHub Desktop.
This is now throwing an error when we run chef-client -i
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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