Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2093db494c16
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6e3b18ca8d5f
Choose a head ref
  • 4 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 12, 2015

  1. Copy the full SHA
    bb3bb81 View commit details
  2. Copy the full SHA
    ae9f191 View commit details

Commits on Mar 13, 2015

  1. Copy the full SHA
    3cb6ca4 View commit details
  2. Merge pull request #745 from vais/struct

    Struct#[] and Struct#[]= fully compliant with rubyspec
    meh committed Mar 13, 2015
    Copy the full SHA
    6e3b18c View commit details
Showing with 8 additions and 7 deletions.
  1. +8 −2 opal/corelib/struct.rb
  2. +0 −5 spec/filters/bugs/struct.rb
10 changes: 8 additions & 2 deletions opal/corelib/struct.rb
Original file line number Diff line number Diff line change
@@ -61,23 +61,29 @@ def members

def [](name)
if Integer === name
raise IndexError, "offset #{name} too small for struct(size:#{members.size})" if name < -members.size
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size

name = members[name]
else
elsif String === name
raise NameError, "no member '#{name}' in struct" unless members.include?(name.to_sym)
else
raise TypeError, "no implicit conversion of #{name.class} into Integer"
end

instance_variable_get "@#{name}"
end

def []=(name, value)
if Integer === name
raise IndexError, "offset #{name} too small for struct(size:#{members.size})" if name < -members.size
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size

name = members[name]
else
elsif String === name
raise NameError, "no member '#{name}' in struct" unless members.include?(name.to_sym)
else
raise TypeError, "no implicit conversion of #{name.class} into Integer"
end

instance_variable_set "@#{name}", value
5 changes: 0 additions & 5 deletions spec/filters/bugs/struct.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
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#[]= fails when trying to assign attributes which don't exist"

fails "Struct#== returns true if the other has all the same fields"
fails "Struct#== handles recursive structures by returning false if a difference can be found"