coercion

Unboxing uint/int without knowing what's inside the box

I have an object o that is known to be a boxed int or uint: object o = int.MinValue object o = (uint)int.MinValue // same bytes as above I don't know what's in the box, all I care about is that there's 4 bytes in there that I want to coerce to an int or uint. This works fine in an unchecked context when I have values (instead of boxes...

Why does Ruby need to force an Array into string by using "to_a" if it is clear it is a String addition?

For example: ruby-1.9.2-p0 > a = ['hello', 'world'] => ["hello", "world"] ruby-1.9.2-p0 > "foo" + a TypeError: can't convert Array into String from (irb):3:in `+' from (irb):3 from /Users/peter/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>' ruby-1.9.2-p0 > "foo" + a.to_s => "foo[\"hello\", \"world\"]" ruby-1.9.2-p0 ...

Perl: fixing Moose attribute and type coercion problems

I recently upgraded Moose to v1.15 and found that a set of modules I use no longer worked. The error I get is: You cannot coerce an attribute (source) unless its type (GOBO::Node) has a coercion at /opt/local/lib/perl5/site_perl/5.12.0/darwin-multi-2level/Moose/Meta/Role/Application/ToClass.pm line 142 I can see several possible sourc...