Favorite Ruby Methods: Part 4 - Enumerables + Bonus Methods
Listen now
Description
On this episode of Ruby for All, Julie tells us she’s fostering a seven week old puppy and having lots of fun, and Andrew reveals he would love to get a dog in the future. Also, it’s the end of the month and you know what that means?  Andrew and Julie are wrapping up their February series on Ruby Methods, so first up, they’ll be discussing the module Enumerable since Andrew learned more about it, we’ll find out about polymorphic record, and then on to the object methods tally, partition, sort by, send, is_a, itself, respond_to, .methods, .tap, strftime, and integer.digits. Thanks for joining us on this journey and we hope you enjoyed this series as much as we did! Download this episode now to hear more!  [00:01:15] Julie and Andrew share how they both felt about this series, and how they love all the support they’ve been getting from the listeners.  [00:03:10] Andrew kicks things off with explaining module Enumerable since he couldn’t explain what it was the other week, he has since learned about it, and now you can too.  [00:05:00] Aside from array and hash, Julie wonders if there are other objects that might pull the enumerable in, like set? [00:07:32] Julie explains the object method tally, which returns a hash containing the counts of equal elements, and we hear some examples. [00:08:52] What is a polymorphic record? [00:10:37] Andrew tells us why he likes flat map, and Julie shares it’s very readable and when she learned to use it [00:13:01] Our next object method is partition, which Julie explains she hasn’t had a chance to use it in practice, and we hear what it does.  [00:15:30] The next object method is sort by, with a block given, returns an array of elements of self, sorted according to the value returned by the block for each element. The ordering of equal elements is indeterminate and may be unstable. [00:17:29] Andrew likes the next object method send, which invokes the method identified by symbol, passing it any arguments specified. When the method is identified by a string, the string is converted to a symbol. Andrew explains this one in depth.  [00:22:33] The next object method is called is_ a, also an alias for kind of, which returns true if class is the class of object.  [00:24:45] Julie put the next object method on the list and Andrew didn’t even know about it! The next object method is itself, which returns the receiver. If anyone knows how to use itself in practice, please let Julie and Andrew know.  [00:25:52] The next object method is respond_to, and when you should use this. [00:27:43] The next object method is .methods, that returns a list of all the methods that are available to that object, and Andrew uses this for debugging. [00:29:28] Coming up now is the object method .tap, which yields self to the block, and then returns self. The primary purpose of this method is to “tap into” a method chain in order to perform operations on intermediate results within the chain. Julie asks Andrew to explain what strong parameters are and what tap does. [00:33:05] Julie’s been using this next object method called strftime, which formats time according to the directives in the given format string. She shares a great resource she used to build, Andrew tells us that Rails has formatted strings, and a website made by Andy Croll.  [00:36:45] We made it to the last object method which is integer.digits, and this returns an array of integers representing that number.  Panelists: Andrew Mason Julie J. Sponsors: Avo Honeybadger Links: Andrew Mason Twitter Andrew Mason Website Julie J. Twitter Julie J. Website module Enumerable tally flat map partition sort by send is_a itself respond to .methods .tap strftime integer digits FOR A GOOD STRFTIME Rails DateTime Formats
More Episodes
In this special crossover episode recorded live from RailsConf 2024 in Detroit, join us for a unique gathering of prominent Ruby podcasters. Julie teams up with Elise from the 'Ruby on Rails' podcast, Jason from 'Code with Jason,' Joël from 'The Bike Shed,' and Drew from 'Code and the Coding...
Published 06/06/24
Published 06/06/24
In this episode of 'Ruby for All', Andrew and Julie discuss drawing inspiration from MC Escher through games like Monument Valley, to dealing with the intricacies of Discord roles and authorization, and the importance of immediate and continuous feedback through tools like Google Docs during...
Published 05/02/24