[前][次][番号順一覧][スレッド一覧]

ruby-changes:15572

From: tenderlove <ko1@a...>
Date: Sun, 25 Apr 2010 05:00:04 +0900 (JST)
Subject: [ruby-changes:15572] Ruby:r27478 (trunk): * ext/psych/lib/psych/deprecated.rb: supporting detect_implicit method

tenderlove	2010-04-25 04:58:34 +0900 (Sun, 25 Apr 2010)

  New Revision: 27478

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27478

  Log:
    * ext/psych/lib/psych/deprecated.rb: supporting detect_implicit method
    * test/psych/test_deprecated.rb: ditto

  Modified files:
    trunk/ext/psych/lib/psych/deprecated.rb
    trunk/ext/psych/lib/psych.rb
    trunk/test/psych/test_deprecated.rb

Index: ext/psych/lib/psych/deprecated.rb
===================================================================
--- ext/psych/lib/psych/deprecated.rb	(revision 27477)
+++ ext/psych/lib/psych/deprecated.rb	(revision 27478)
@@ -30,6 +30,12 @@
     list.each(&block)
   end
 
+  def self.detect_implicit thing
+    warn "#{caller[0]}: detect_implicit is deprecated" if $VERBOSE
+    return '' unless String === thing
+    return 'null' if '' == thing
+    ScalarScanner.new.tokenize(thing).class.name.downcase
+  end
 end
 
 class Object
Index: ext/psych/lib/psych.rb
===================================================================
--- ext/psych/lib/psych.rb	(revision 27477)
+++ ext/psych/lib/psych.rb	(revision 27478)
@@ -241,6 +241,5 @@
     attr_accessor :dump_tags
     attr_accessor :domain_types
   end
-
   # :startdoc:
 end
Index: test/psych/test_deprecated.rb
===================================================================
--- test/psych/test_deprecated.rb	(revision 27477)
+++ test/psych/test_deprecated.rb	(revision 27478)
@@ -163,5 +163,13 @@
 
       assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
     end
+
+    def test_detect_implicit
+      assert_equal '', Psych.detect_implicit(nil)
+      assert_equal '', Psych.detect_implicit(Object.new)
+      assert_equal '', Psych.detect_implicit(1.2)
+      assert_equal 'null', Psych.detect_implicit('')
+      assert_equal 'string', Psych.detect_implicit('foo')
+    end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]