Project

General

Profile

Feature #6276

to_h as explicit conversion to Hash

Added by marcandre (Marc-Andre Lafortune) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:44269]

Description

Dear Matz.

We should establish #to_h as the method for explicit conversion to Hash:

1) Add Hash#to_h: returns self for Hash, or a Hash for subclasses of Hash
2) Add Struct#to_h: as requested in Feature #4862 under the wrong name
3) Add OpenStruct#to_h: see Feature #1400

In addition, please consider adding NilClass#to_h.

Even though you are not completely satisfied with NilClass#to_a, I use it very often. If we ever have something equivalent to the splat operator for hashes, the same hesitations will apply to nil.to_h, but I feel it would still bring more good than problems.

Thanks


Related issues

Related to Ruby trunk - Feature #5008: Equal rights for Hash (like Array, String, Integer, Float)Rejected2011-07-10

Associated revisions

Revision 35339
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Add Hash#to_h [Feature #6276]
[rubyspec:84b7fe3f24d2]

Revision 35339
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Add Hash#to_h [Feature #6276]
[rubyspec:84b7fe3f24d2]

Revision 35339
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Add Hash#to_h [Feature #6276]
[rubyspec:84b7fe3f24d2]

Revision 35339
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Add Hash#to_h [Feature #6276]
[rubyspec:84b7fe3f24d2]

Revision 35340
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* object.c: Add NilClass#to_h [Feature #6276]
[ref #5008] [rubyspec:dc5ecddbd608]

Revision 35340
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* object.c: Add NilClass#to_h [Feature #6276]
[ref #5008] [rubyspec:dc5ecddbd608]

Revision 35340
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* object.c: Add NilClass#to_h [Feature #6276]
[ref #5008] [rubyspec:dc5ecddbd608]

Revision 35340
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* object.c: Add NilClass#to_h [Feature #6276]
[ref #5008] [rubyspec:dc5ecddbd608]

Revision 35341
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* struct.c: Add Struct#to_h [Feature #6276]
[ref #4862] [rubyspec:2082ef46d46e]

Revision 35341
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* struct.c: Add Struct#to_h [Feature #6276]
[ref #4862] [rubyspec:2082ef46d46e]

Revision 35341
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* struct.c: Add Struct#to_h [Feature #6276]
[ref #4862] [rubyspec:2082ef46d46e]

Revision 35341
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* struct.c: Add Struct#to_h [Feature #6276]
[ref #4862] [rubyspec:2082ef46d46e]

Revision 35342
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]
[ref #1400] [rubyspec:9e0250b2fc6f]

Revision 35342
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]
[ref #1400] [rubyspec:9e0250b2fc6f]

Revision 35342
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]
[ref #1400] [rubyspec:9e0250b2fc6f]

Revision 35342
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]
[ref #1400] [rubyspec:9e0250b2fc6f]

Revision 35343
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]
[rubyspec:6587eead7cd1]

Revision 35343
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]
[rubyspec:6587eead7cd1]

Revision 35343
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]
[rubyspec:6587eead7cd1]

Revision 35343
Added by marcandre (Marc-Andre Lafortune) over 5 years ago

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]
[rubyspec:6587eead7cd1]

Revision 35383
Added by naruse (Yui NARUSE) over 5 years ago

Revert r35339 because of no tests.

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

* struct.c: Add Struct#to_h [Feature #6276]

* object.c: Add NilClass#to_h [Feature #6276]

* hash.c: Add Hash#to_h [Feature #6276]

Revision 35383
Added by naruse (Yui NARUSE) over 5 years ago

Revert r35339 because of no tests.

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

* struct.c: Add Struct#to_h [Feature #6276]

* object.c: Add NilClass#to_h [Feature #6276]

* hash.c: Add Hash#to_h [Feature #6276]

Revision 35383
Added by naruse (Yui NARUSE) over 5 years ago

Revert r35339 because of no tests.

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

* struct.c: Add Struct#to_h [Feature #6276]

* object.c: Add NilClass#to_h [Feature #6276]

* hash.c: Add Hash#to_h [Feature #6276]

Revision 35383
Added by naruse (Yui NARUSE) over 5 years ago

Revert r35339 because of no tests.

* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

* struct.c: Add Struct#to_h [Feature #6276]

* object.c: Add NilClass#to_h [Feature #6276]

* hash.c: Add Hash#to_h [Feature #6276]

Revision 35452
Added by nobu (Nobuyoshi Nakada) over 5 years ago

* hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]

Revision 35452
Added by nobu (Nobuyoshi Nakada) over 5 years ago

* hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]

Revision 35452
Added by nobu (Nobuyoshi Nakada) over 5 years ago

* hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]

Revision 35452
Added by nobu (Nobuyoshi Nakada) over 5 years ago

* hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]

History

#1 [ruby-core:44282] Updated by matz (Yukihiro Matsumoto) over 5 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to marcandre (Marc-Andre Lafortune)

OK, accepted, include adding nil.to_h.
Marc, could you make patch and check in?

Matz.

#2 [ruby-core:44283] Updated by marcandre (Marc-Andre Lafortune) over 5 years ago

Great.

I'll do it with pleasure, expect a slight delay as I'm going in vacation for 10 days.

Thanks

#3 Updated by marcandre (Marc-Andre Lafortune) over 5 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35339.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • hash.c: Add Hash#to_h [Feature #6276] [rubyspec:84b7fe3f24d2]

#4 [ruby-core:44380] Updated by naruse (Yui NARUSE) over 5 years ago

  • Status changed from Closed to Assigned

You didn't add tests for test-all.
If you won't add them, I'll revert them.

#5 [ruby-core:44386] Updated by nahi (Hiroshi Nakamura) over 5 years ago

+1 to Naruse-san. Apparently test in the same repository is a must.

#6 Updated by naruse (Yui NARUSE) over 5 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r35383.
Marc-Andre, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Revert r35339 because of no tests.

  • hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

  • lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

  • struct.c: Add Struct#to_h [Feature #6276]

  • object.c: Add NilClass#to_h [Feature #6276]

  • hash.c: Add Hash#to_h [Feature #6276]

Also available in: Atom PDF