Guest User

Untitled

a guest
Jul 19th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. From e548d8e62065232151e80bd1a58234885c14db64 Mon Sep 17 00:00:00 2001
  2. From: David Calavera <david.calavera@gmail.com>
  3. Date: Tue, 4 Jan 2011 19:16:28 +0100
  4. Subject: [PATCH 1/2] Module.const_defined? accepts a flag to search into the receiver superclasses
  5.  
  6. ---
  7. core/module/const_defined_spec.rb | 8 ++++++++
  8. 1 files changed, 8 insertions(+), 0 deletions(-)
  9.  
  10. diff --git a/core/module/const_defined_spec.rb b/core/module/const_defined_spec.rb
  11. index c8face6..d95ceef 100644
  12. --- a/core/module/const_defined_spec.rb
  13. +++ b/core/module/const_defined_spec.rb
  14. @@ -19,6 +19,14 @@ describe "Module#const_defined?" do
  15. # CS_CONST10 is defined in a module included by ChildA
  16. ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true
  17. end
  18. +
  19. + it "returns false if the constant is defined in the receiver's superclass and the inherit flag is false" do
  20. + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should be_false
  21. + end
  22. +
  23. + it "returns true if the constant is defined in the receiver's superclass and the inherit flag is true" do
  24. + ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should be_true
  25. + end
  26. end
  27.  
  28. it "returns true if the given String names a constant defined in the receiver" do
  29. --
  30. 1.7.2.3
  31.  
  32.  
  33. From be1b0d4bca3f588d8ec966c4e41c8bbd049e6040 Mon Sep 17 00:00:00 2001
  34. From: David Calavera <david.calavera@gmail.com>
  35. Date: Tue, 4 Jan 2011 19:16:46 +0100
  36. Subject: [PATCH 2/2] Module.const_get accepts a flag to search into the receiver superclasses
  37.  
  38. ---
  39. core/module/const_get_spec.rb | 12 ++++++++++++
  40. 1 files changed, 12 insertions(+), 0 deletions(-)
  41.  
  42. diff --git a/core/module/const_get_spec.rb b/core/module/const_get_spec.rb
  43. index c3b6641..d1fdd99 100644
  44. --- a/core/module/const_get_spec.rb
  45. +++ b/core/module/const_get_spec.rb
  46. @@ -61,6 +61,18 @@ describe "Module#const_get" do
  47. end.should raise_error(NameError)
  48. end
  49.  
  50. + ruby_version_is "1.9" do
  51. + it "raises a NameError if the constant is defined in the receiver's supperclass and the inherit flag is false" do
  52. + lambda do
  53. + ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, false)
  54. + end.should raise_error(NameError)
  55. + end
  56. +
  57. + it "searches into the receiver superclasses if the inherit flag is true" do
  58. + ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, true).should == :const4
  59. + end
  60. + end
  61. +
  62. describe "with statically assigned constants" do
  63. it "searches the immediate class or module first" do
  64. ConstantSpecs::ClassA.const_get(:CS_CONST10).should == :const10_10
  65. --
  66. 1.7.2.3
Add Comment
Please, Sign In to add comment