Created
August 9, 2018 14:58
-
-
Save TvL2386/98313758cfd527b2bb9dd07bec4ba225 to your computer and use it in GitHub Desktop.
This file contains 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 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