Project

General

Profile

Bug #11776

dig and custom objects

Added by marcandre (Marc-Andre Lafortune) over 3 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
2.3.0 preview
[ruby-core:71853]

Description

Although currently undocumented and untested, it is possible to dig objects of any class that implements dig:

class Foo
  def dig(x, *)
    40 + x
  end
end

{hello: Foo.new}.dig(:hello, 2) # => 42

This seems actually quite nice to me.

Matz, could you confirm that this is part of the new feature? I'll fix the documentation and add some basic tests

Associated revisions

Revision cb3b463a
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52941
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

Revision 52941
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

Revision 52941
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

Revision 52941
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

Revision 52941
Added by marcandre (Marc-Andre Lafortune) over 3 years ago

  • array.c: Improve and fix documentation for Array#dig
    [#11776]

  • hash.c: ditto

  • struct.c: ditto

  • test_hash.rb: Add basic test for user defined dig.

History

Updated by matz (Yukihiro Matsumoto) over 3 years ago

Confirmed. ;-)

Matz.

#3

Updated by marcandre (Marc-Andre Lafortune) over 1 year ago

  • Status changed from Open to Closed

Also available in: Atom PDF