

It returns the value of the last expression evaluated in the block. Proccall invokes the block, setting the block’s parameters to the values in params using something close to method calling semantics.


TweetCreator is a nice short class name, but the extra cruft around instantiating the object and calling the method is just too long! If only there were precedence in Ruby for calling something and having it execute itself immediately with the given parameters… oh wait, there is! It’s Proc#call. I guess that’s another article for another time. In all seriousness, though, why do people use HTML when HAML is around? Or even Slim. It’s far too verbose with redundant words… much like HTML (ba-dum tiss!). Look, this feels great in theory, but TweetCreator.new(params).send_tweet is just a mouthful. Adding Syntactic Sugar to Make Rails Service Objects Suck Less Want to know more about how autoload works? Read the Autoloading and Reloading Constants Guide. Users/gilani/Sandbox/nazdeeq/app/services If you’ve been using vanilla Rails so far, then you’ve probably done something like this: class TweetController puts ActiveSupport::toload_paths Try this: What do you do when your application needs to tweet the text from params?
Try method map rails how to#
In this article, I’ll explain when a service object is required how to go about writing clean service objects and grouping them together for contributor sanity the strict rules I impose on my service objects to tie them directly to my business logic and how not to turn your service objects into a dumping ground for all the code you don’t know what to do with. When your business logic can’t fit into either a model or a controller, that’s when service objects come in and let us separate every business action into its own Ruby object. Ruby on Rails ships with everything you need to prototype your application quickly, but when your codebase starts growing, you’ll run into scenarios where the conventional Fat Model, Skinny Controller mantra breaks.
