Sha256: 728e85b8978cfc1731d870bfed4a4c2bb1fdcd76be04358ad83ec0aaa123bc3b
Contents?: true
Size: 1.56 KB
Versions: 7
Compression:
Stored size: 1.56 KB
Contents
#-- # YAMLStruct # # Copyright (c) 2005 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or redistribute this # software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. # # ========================================================================== # Revision History # ========================================================================== # 2005-09-13 trans Created. # ========================================================================== # # TODO Currently only supports YAML documents with a map at the top level. # #++ require 'yaml' #:title: YAMLStruct # # TODO # # == Author(s) # # * Thomas Sawyer # class YAMLStruct def initialize( stream ) @yaml = YAML::load( stream ) end def method_missing( sym, *args, &blk ) sym = sym.to_s if sym.slice(-1,1) == '=' @yaml[ sym ] = args[0] elsif @yaml.key?( sym ) @yaml[ sym ] else #raise ? end end def to_s @yaml.to_yaml end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TC_YAMLStruct < Test::Unit::TestCase def setup y = %{ a: 1 b: 2 c: 3 } @y = YAMLStruct.new(y) end def test_001 assert_equal( 1, @y.a ) assert_equal( 2, @y.b ) assert_equal( 3, @y.c ) end end =end
Version data entries
7 entries across 7 versions & 1 rubygems