Skip to content

Loading…

Re-order methods #130

Closed
wants to merge 3 commits into from

3 participants

@sheerun

No description provided.

@zzak
Collaborator

Was the purpose of this change just to re-order the methods?

@zzak zzak was assigned
@sheerun

Yes

@tenderlove tenderlove closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 38 deletions.
  1. +38 −38 lib/psych.rb
View
76 lib/psych.rb
@@ -131,6 +131,38 @@ def self.load yaml, filename = nil
end
###
+ # Load the document contained in +filename+. Returns the yaml contained in
+ # +filename+ as a ruby object
+ def self.load_file filename
+ File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
+ end
+
+ ###
+ # Load multiple documents given in +yaml+. Returns the parsed documents
+ # as a list. If a block is given, each document will be converted to ruby
+ # and passed to the block during parsing
+ #
+ # Example:
+ #
+ # Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
+ #
+ # list = []
+ # Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby|
+ # list << ruby
+ # end
+ # list # => ['foo', 'bar']
+ #
+ def self.load_stream yaml, filename = nil
+ if block_given?
+ parse_stream(yaml, filename) do |node|
+ yield node.to_ruby
+ end
+ else
+ parse_stream(yaml, filename).children.map { |child| child.to_ruby }
+ end
+ end
+
+ ###
# Parse a YAML string in +yaml+. Returns the first object of a YAML AST.
# +filename+ is used in the exception message if a Psych::SyntaxError is
# raised.
@@ -167,12 +199,6 @@ def self.parse_file filename
end
###
- # Returns a default parser
- def self.parser
- Psych::Parser.new(TreeBuilder.new)
- end
-
- ###
# Parse a YAML string in +yaml+. Returns the full AST for the YAML document.
# This method can handle multiple YAML documents contained in +yaml+.
# +filename+ is used in the exception message if a Psych::SyntaxError is
@@ -211,6 +237,12 @@ def self.parse_stream yaml, filename = nil, &block
end
###
+ # Returns a default parser
+ def self.parser
+ Psych::Parser.new(TreeBuilder.new)
+ end
+
+ ###
# call-seq:
# Psych.dump(o) -> string of yaml
# Psych.dump(o, options) -> string of yaml
@@ -267,38 +299,6 @@ def self.to_json o
visitor.tree.yaml
end
- ###
- # Load multiple documents given in +yaml+. Returns the parsed documents
- # as a list. If a block is given, each document will be converted to ruby
- # and passed to the block during parsing
- #
- # Example:
- #
- # Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
- #
- # list = []
- # Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby|
- # list << ruby
- # end
- # list # => ['foo', 'bar']
- #
- def self.load_stream yaml, filename = nil
- if block_given?
- parse_stream(yaml, filename) do |node|
- yield node.to_ruby
- end
- else
- parse_stream(yaml, filename).children.map { |child| child.to_ruby }
- end
- end
-
- ###
- # Load the document contained in +filename+. Returns the yaml contained in
- # +filename+ as a ruby object
- def self.load_file filename
- File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
- end
-
# :stopdoc:
@domain_types = {}
def self.add_domain_type domain, type_tag, &block
Something went wrong with that request. Please try again.