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: 9741c7e80fd1
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f671c464cfb7
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Mar 17, 2015

  1. Copy the full SHA
    a658052 View commit details
  2. Merge pull request #757 from vais/struct

    Struct#values_at fully compliant with rubyspec
    meh committed Mar 17, 2015
    Copy the full SHA
    f671c46 View commit details
Showing with 14 additions and 3 deletions.
  1. +14 −0 opal/corelib/struct.rb
  2. +0 −3 spec/filters/bugs/struct.rb
14 changes: 14 additions & 0 deletions opal/corelib/struct.rb
Original file line number Diff line number Diff line change
@@ -142,4 +142,18 @@ def inspect
def to_h
members.inject({}) {|h, name| h[name] = self[name]; h}
end

def values_at(*args)
args = args.map{|arg| `arg.$$is_range ? #{arg.to_a} : arg`}.flatten
%x{
var result = [];
for (var i = 0, len = args.length; i < len; i++) {
if (!args[i].$$is_number) {
#{raise TypeError, "no implicit conversion of #{`args[i]`.class} into Integer"}
}
result.push(#{self[`args[i]`]});
}
return result;
}
end
end
3 changes: 0 additions & 3 deletions spec/filters/bugs/struct.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,4 @@
fails "Struct.new does not create a constant with symbol as first argument"
fails "Struct.new creates a new anonymous class with nil first argument"
fails "Struct.new calls to_str on its first argument (constant name)"

fails "Struct#values_at fails when passed unsupported types"
fails "Struct#values_at returns an array of values"
end