Project

General

Profile

Actions

Bug #16086

closed

OpenStruct method access with a block does not raise

Added by kke (Kimmo Lehto) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:94195]

Description

This can cause confusion.

  > OpenStruct.new(hello: 'world').each { |k, v| puts k.upcase } # there's no "each" method
  => nil
  > OpenStruct.new(hello: 'world').eahc_pair { |k, v| puts k.upcase } # each_pair typo
  => nil

An undefined key with a block should maybe raise NoMethodError or ArgumentError?

A defined key with a block seems to yield the value, I don't see this being documented:

  > OpenStruct.new(hello: 'world').hello { |k| puts k.upcase } 
  HELLO

Maybe it should raise ArgumentError too?

Related: https://bugs.ruby-lang.org/issues/15515

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0