Skip to content
Permalink
Browse files

NodeMixin#initialize yield self to block [82]

  • Loading branch information...
jho406 committed Oct 6, 2009
1 parent 8af54bd commit 96d724d150d7c050faa1bda3b498912e918c38ef
Showing with 11 additions and 0 deletions.
  1. +1 −0 lib/neo4j/mixins/node_mixin.rb
  2. +10 −0 test/neo4j/node_mixin_spec.rb
@@ -35,6 +35,7 @@ def initialize(*args)
init_without_node
init_node(*args) if self.respond_to?(:init_node)
end
yield self if block_given?
# must call super with no arguments so that chaining of the initialize method works
super()
end
@@ -77,6 +77,16 @@ class TestNode4
node2 = TestNode4.new(node1.internal_node)
node1.internal_node.should == node2.internal_node
end

it "should accept a block and pass self as parameter" do
class TestNode5
include Neo4j::NodeMixin
property :foo
end

node1 = TestNode5.new {|n| n.foo = 'hi'}
node1.foo.should == 'hi'
end
end


2 comments on commit 96d724d

@andreasronge

This comment has been minimized.

Copy link

replied Oct 6, 2009

Yes, I removed this feature. I can't remember why. But if you think this feature is useful maybe we should add it again.

@jho406

This comment has been minimized.

Copy link
Owner Author

replied Oct 6, 2009

I actually prefered if it accepted a hash. something like this:

class TestNode5
  include Neo4j::NodeMixin
  property :foo, :blaz
end

TestNode5.new(:foo=>"hello", :blaz=>"world")

or if the property order can be tracked:

TestNode5.new("hello","world")

What do you think?

Please sign in to comment.
You can’t perform that action at this time.