Java guilt

On Mar 16, 12:49 pm, Pit C. [email protected] wrote:

end
the outside to tryme? And what would happen if I use a string created in
InBlanket outside of the class?

Good point, Pit. The String defined outside would not be effected.
Most data comes from the outside, so there’s really no point to this
unless the incoming data is recast into the extended version
automatically (or manually?).

T.

On Sat, Mar 17, 2007 at 01:45:03AM +0900, Pit C. wrote:

class while executing code in some other class. This is probably expensive
as
hell and non-trivial to implement. But it sure would be great to have as it
would make Ruby a “safer” language.

Jos, we’ve talked about this two months ago on ruby-core. Maybe it’s
only the syntax of libraries like “import-module” which you don’t like,
but I think they can do what you want. See below.

Indeed we did.

class Bar

b.hello(1) rescue puts “no Fixnum#foo” # => no Fixnum#foo
“Pit”.foo rescue puts “no String#foo” # => no String#foo

You can see that #foo is added to String but is only visible within
class Bar. (The implementation is a quick and dirty hack, though.)

That’s sweet! This does indeed seem to do what I’m looking for. Thanks
Pit!
And Tom, too. :slight_smile:

If I wanted this to be used inside class Baz, too, would I stick foo' in a module and useextending’ with that module somehow? I need to go check
out
`import-module-extended’…

If it’s a hacky implementation, how could it be cleaned up? This would
be
great to have as part of stdlib.

Cheers,

On Mar 16, 9:23 pm, Logan C. [email protected] wrote:

some
without having to subclass String and use it inside of Bar instead of
extending(String) do
name ||= @name
“Pit”.foo rescue puts “no String#foo” # => no String#foo

class Bar
def hello2
Q.new(“hmm”)
end
end

Bar.new.hello2

More importantly than what does happen, is what should happen?

It should raise an error. #foo is not defined for String in the scope
of Q. Which is why my idea doesn’t work --at least not as I originally
conceived it.

Any efficient implementation of this becomes quite a problem I
imagine. Seems like it would require all objects to be references, so
they could become any other type on the fly.

T.

On Sat, Mar 17, 2007 at 01:45:03AM +0900, Pit C. wrote:

class while executing code in some other class. This is probably expensive
String
def foo
puts(name.foo)

You can see that #foo is added to String but is only visible within
class Bar. (The implementation is a quick and dirty hack, though.)
What happens if I do
class Q
def initialize(s)
s.foo
end
end

class Bar
def hello2
Q.new(“hmm”)
end
end

Bar.new.hello2

More importantly than what does happen, is what should happen?