oop - Ruby class associations -



oop - Ruby class associations -

i'm having problem creating class association in ruby, since it's dynamic typed language. in java, write this:

public class foo { ... } public class bar { public foo foo; ... }

how can write similar in ruby?

class foo end class bar attr_accessor :foo def initialize (foo) @foo = foo end end foo = foo.new bar = bar.new(foo) puts bar.foo

for say, seems need kind of type safety. can accomplish doing

def initialize (foo) raise argumenterror, "you must provide valid foo instance" unless foo.instace_of?(foo) @foo = foo end

ruby oop associations

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -