tag:blogger.com,1999:blog-8326467133854092913.post1443435803745610480..comments2023-06-02T08:41:00.844+01:00Comments on smartrics: Method chaining with Rubysmartricshttp://www.blogger.com/profile/07295654362099098666noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8326467133854092913.post-47650032351593396962010-11-27T23:41:05.510+00:002010-11-27T23:41:05.510+00:00Joshua, fair point on constructing objects using t...Joshua, fair point on constructing objects using the more idiomatic form in generic ruby code.<br /><br />I am (was) building a DSL and I opted to provide users with a single "look&feel" by means of method chaining for the initialization of domain objectssmartricshttps://www.blogger.com/profile/07295654362099098666noreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-27061730750288654252010-11-25T22:08:42.675+00:002010-11-25T22:08:42.675+00:00Thanks for the article. Of course, though, the exa...Thanks for the article. Of course, though, the examples are not the way you construct an object. Rather:<br /><br />Person.new(:firstname=>"Bob", :surname=>"Smith")<br /><br />as idiomatic. I would strongly urge Rubyists to *not* build object (particularly those in the domain model) using this mechanism.<br /><br />Method chaining is useful on objects when they are immutable and you are using some "tell-don't-ask" methods to end up with a new immutable object (the original one perhaps no longer being reference and garbage collected).<br /><br />Method chaining is best suited for fluent interfaces (as you mentioned), especially on APIs where you are providing a series of commands to transform data like you might with Unix "pipes".<br /><br />RSpec is a great example of this, particularly RSpec 2.<br /><br />Cheers,<br />JoshGAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-75108165102290697532010-10-24T02:43:37.133+01:002010-10-24T02:43:37.133+01:00interesting article, thanksinteresting article, thanksMelody Classnoreply@blogger.comtag:blogger.com,1999:blog-8326467133854092913.post-76610682627856008372010-04-22T08:29:03.480+01:002010-04-22T08:29:03.480+01:00kudos for you!kudos for you!Manrico Corazzihttps://www.blogger.com/profile/10866541980869905892noreply@blogger.com