Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Struct.[] as synonym for Struct.new
  • Loading branch information
adambeynon committed Dec 9, 2013
1 parent 6c29774 commit bd10abe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -84,7 +84,7 @@
is present (`a = 0; a [0]` parses as a deference on a).

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

## 0.5.5 2013-11-25

Expand Down
4 changes: 4 additions & 0 deletions opal/corelib/struct.rb
Expand Up @@ -49,6 +49,10 @@ def self.inherited(klass)
}
end

class << self
alias [] new
end

include Enumerable

def initialize(*args)
Expand Down
4 changes: 4 additions & 0 deletions spec/opal/filters/bugs/struct.rb
@@ -1,5 +1,9 @@
opal_filter "Struct" do
fails "Struct#[] fails when it does not know about the requested attribute"
fails "Struct#[] fails if not passed a string, symbol, or integer"

fails "Struct#initialize can be overriden"

fails "Struct.new fails with too many arguments"
fails "Struct.new creates a constant in subclass' namespace"
fails "Struct.new raises a TypeError if object is not a Symbol"
Expand Down
1 change: 1 addition & 0 deletions spec/opal/rubyspecs
Expand Up @@ -319,6 +319,7 @@ core/symbol/to_proc_spec

core/struct/each_pair_spec
core/struct/each_spec
core/struct/element_reference_spec
core/struct/initialize_spec
core/struct/new_spec

Expand Down

0 comments on commit bd10abe

Please sign in to comment.