module Psychgus::Ext::ObjectExt
Core extensions to Object.
@author Jonathan Bradley Whited @since 1.0.0
@see github.com/ruby/psych/blob/master/lib/psych/core_ext.rb
Public Instance Methods
to_yaml(**options)
click to toggle source
Convert an Object to YAML.
options
can also be a Hash, so can be a drop-in-replacement for Psych.
@example
class MyStyler include Psychgus::Styler def style_sequence(sniffer,node) node.style = Psychgus::SEQUENCE_FLOW end end my_obj = { :Foods => { :Fruits => %w(Apple Banana Blueberry Pear), :Veggies => %w(Bean Carrot Celery Pea) }} puts my_obj.to_yaml(indentation: 5,stylers: MyStyler.new) # Or, pass in a Hash: #puts my_obj.to_yaml({:indentation=>5,:stylers=>MyStyler.new}) # Output: # --- # :Foods: # :Fruits: [Apple, Banana, Blueberry, Pear] # :Veggies: [Bean, Carrot, Celery, Pea]
@param options [Hash] the options (or keyword args) to pass to {Psychgus.dump}
@return [String] the YAML generated from this Object
@see Psychgus.dump
# File lib/psychgus/ext/core_ext.rb, line 58 def to_yaml(**options) # Do not use Psych.dump() if no Stylers, because a class might be a Blueberry return Psychgus.dump(self,**options) end