Module: Psychgus::Ext::ObjectExt

Defined in:
lib/psychgus/ext/core_ext.rb

Overview

Core extensions to Object.

See Also:

Author:

  • Jonathan Bradley Whited (@esotericpig)

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#to_yaml(**options) ⇒ String

Convert an Object to YAML.

options can also be a Hash, so can be a drop-in-replacement for Psych.

Examples:

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]

Parameters:

  • options (Hash)

    the options (or keyword args) to pass to Psychgus.dump

Returns:

  • (String)

    the YAML generated from this Object

See Also:

Since:

  • 1.0.0


69
70
71
72
# File 'lib/psychgus/ext/core_ext.rb', line 69

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