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

Commits on Apr 26, 2015

  1. Copy the full SHA
    003c47a View commit details

Commits on May 1, 2015

  1. Merge pull request #2877 from alno/big_decimal_dup

    Implementation of initialize_copy for BigDecimal (fix #2868)
    enebo committed May 1, 2015
    Copy the full SHA
    fff5f98 View commit details
Showing with 34 additions and 3 deletions.
  1. +24 −3 core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
  2. +10 −0 spec/regression/GH-2868_big_decimal_can_not_be_copied_spec.rb
27 changes: 24 additions & 3 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Original file line number Diff line number Diff line change
@@ -153,9 +153,9 @@ public static RubyClass createBigDecimal(Ruby runtime) {
return null;
}

private final boolean isNaN;
private final int infinitySign;
private final int zeroSign;
private boolean isNaN;
private int infinitySign;
private int zeroSign;
private BigDecimal value;

public BigDecimal getValue() {
@@ -594,6 +594,27 @@ public RubyFixnum hash() {
return getRuntime().newFixnum(value.stripTrailingZeros().hashCode());
}

@Override
@JRubyMethod(name = "initialize_copy", visibility = Visibility.PRIVATE)
public IRubyObject initialize_copy(IRubyObject original) {
if (this == original) return this;

checkFrozen();

if (!(original instanceof RubyBigDecimal)) {
throw getRuntime().newTypeError("wrong argument class");
}

RubyBigDecimal origRbd = (RubyBigDecimal)original;

this.isNaN = origRbd.isNaN;
this.infinitySign = origRbd.infinitySign;
this.zeroSign = origRbd.zeroSign;
this.value = origRbd.value;

return this;
}

public IRubyObject op_mod(ThreadContext context, IRubyObject arg) {
return op_mod19(context, arg);
}
10 changes: 10 additions & 0 deletions spec/regression/GH-2868_big_decimal_can_not_be_copied_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rspec'
require 'bigdecimal'

describe 'BigDecimal' do
it 'should be duplicable' do
a = BigDecimal.new(1)

expect(a.dup).to eq(a)
end
end