aboutsummaryrefslogtreecommitdiffstats
path: root/lib/yaml.rb
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-15 05:04:49 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-15 05:04:49 +0000
commit3ac79892be7f3473d79ed0868f8413804e279f40 (patch)
tree05b72c2cfc9f3ce039949d8db3b49c4e310c152a /lib/yaml.rb
parent13d4e3b5cdd1b64913446cc42825db3da4ec424a (diff)
downloadruby-3ac79892be7f3473d79ed0868f8413804e279f40.tar.gz
* lib/yaml.rb (YAML::load_file, YAML::parse_file): added.
* ext/syck/token.c: re2c compiled with bit vectors now. * ext/syck/implicit.c: ditto. * ext/syck/bytecode.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml.rb')
-rw-r--r--lib/yaml.rb40
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb
index 023c4ab84b..38463404bd 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -105,7 +105,7 @@ module YAML
end
#
- # Load the first document from the current _io_ stream.
+ # Load a document from the current _io_ stream.
#
# File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) }
# #=> ['badger', 'elephant', 'tiger']
@@ -119,6 +119,18 @@ module YAML
yp = @@parser.new.load( io )
end
+ #
+ # Load a document from the file located at _filepath_.
+ #
+ # YAML.load_file( 'animals.yaml' )
+ # #=> ['badger', 'elephant', 'tiger']
+ #
+ def YAML.load_file( filepath )
+ File.open( filepath ) do |f|
+ load( f )
+ end
+ end
+
#
# Parse the first document from the current _io_ stream
#
@@ -150,6 +162,32 @@ module YAML
yp = @@parser.new( :Model => :Generic ).load( io )
end
+ #
+ # Parse a document from the file located at _filepath_.
+ #
+ # YAML.parse_file( 'animals.yaml' )
+ # #=> #<YAML::Syck::Node:0x82ccce0
+ # @kind=:seq,
+ # @value=
+ # [#<YAML::Syck::Node:0x82ccd94
+ # @kind=:scalar,
+ # @type_id="str",
+ # @value="badger">,
+ # #<YAML::Syck::Node:0x82ccd58
+ # @kind=:scalar,
+ # @type_id="str",
+ # @value="elephant">,
+ # #<YAML::Syck::Node:0x82ccd1c
+ # @kind=:scalar,
+ # @type_id="str",
+ # @value="tiger">]>
+ #
+ def YAML.parse_file( filepath )
+ File.open( filepath ) do |f|
+ parse( f )
+ end
+ end
+
#
# Calls _block_ with each consecutive document in the YAML
# stream contained in _io_.