Skip to content

Instantly share code, notes, and snippets.

@TvL2386
Created August 9, 2018 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TvL2386/98313758cfd527b2bb9dd07bec4ba225 to your computer and use it in GitHub Desktop.
Save TvL2386/98313758cfd527b2bb9dd07bec4ba225 to your computer and use it in GitHub Desktop.
class MailTruck
attr_accessor :driver, :route
def initialize( driver, route )
@driver, @route = driver, route
end
end
m = MailTruck.new( "Harold", ['12 Corrigan Way', '23 Antler Ave'] )
m.instance_variable_set('@speed', 45)
require 'yaml'
class << m
def to_yaml_properties
%w(@driver @route)
end
end
# or do:
def m.to_yaml_properties
%w(@driver @route)
end
puts YAML::dump(m)
=begin
Expected output:
--- !ruby/object:MailTruck
driver: Harold
route:
- 12 Corrigan Way
- 23 Antler Ave
Output:
--- !ruby/object:MailTruck
driver: Harold
route:
- 12 Corrigan Way
- 23 Antler Ave
speed: 45
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment