Skip to content

Commit bd10abe

Browse files
committed
Add Struct.[] as synonym for Struct.new
1 parent 6c29774 commit bd10abe

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
is present (`a = 0; a [0]` parses as a deference on a).
8585

8686
* Fix various `Struct` methods. Fixed `#each` and `#each_pair` to return
87-
self.
87+
self. Add `Struct.[]` as synonym for `Struct.new`.
8888

8989
## 0.5.5 2013-11-25
9090

opal/corelib/struct.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def self.inherited(klass)
4949
}
5050
end
5151

52+
class << self
53+
alias [] new
54+
end
55+
5256
include Enumerable
5357

5458
def initialize(*args)

spec/opal/filters/bugs/struct.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
opal_filter "Struct" do
2+
fails "Struct#[] fails when it does not know about the requested attribute"
3+
fails "Struct#[] fails if not passed a string, symbol, or integer"
4+
25
fails "Struct#initialize can be overriden"
6+
37
fails "Struct.new fails with too many arguments"
48
fails "Struct.new creates a constant in subclass' namespace"
59
fails "Struct.new raises a TypeError if object is not a Symbol"

spec/opal/rubyspecs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ core/symbol/to_proc_spec
319319

320320
core/struct/each_pair_spec
321321
core/struct/each_spec
322+
core/struct/element_reference_spec
322323
core/struct/initialize_spec
323324
core/struct/new_spec
324325

0 commit comments

Comments
 (0)