Here comes stupid question time. I’ve been trying to learn JRuby, got
stuck on learning the monkeybars GUI because of a failure to load
So, I thought I’d roll up my sleeves and try to pitch in to make some
RubySpecs pass. I thought I’d start with a simple-looking failing spec.
The problem is, I don’t understand the rationale, and was wondering if
anyone could give me a hand. Here it is:
it "calls #to_s on arguments that are neither Strings nor Encodings"
string = mock('string') string.should_receive(:to_str).twice.and_return('US-ASCII') Encoding.default_external = string Encoding.default_external.should == Encoding::ASCII end
Can anyone explain? I’ve looked at the C implementation, and the only
reason I see to_str being called twice is first, to convert to a string
make sure that the encoding is ASCII-compatible, and then a second time
get a string used to look up the encoding. As far as I can tell this is
implementation detail, and the JRuby implementation doesn’t need the
call because it just uses the same string object for both the ASCII
and the actual encoding lookup. Perhaps I’m missing something…