Noel Rappin Writes Here

Tag: better_know

Better Know A Ruby Thing #5: Block Arguments

Previously in what what I guess is now “The Argument Trilogy”, we talked about: Positional Arguments Keyword Arguments And now the trilogy now comes to its inevitable conclusion with “Return of The Jedi” block arguments. In the interest of keeping this thing within the plausible word count of a newsletter, we’re not going to talk about what blocks are or the way blocks behave here, that’ll be a future Better Know, but we do need to talk about block syntax.

Better Know A Ruby Thing #4: Keyword Arguments

Last time on Better Know A Ruby Thing, we covered positional arguments, and now we’re going to move on to keyword arguments. I really did think this was going to be shorter than the last one, and then I got to the conversion between keyword and positional arguments, and then… well, it’s not shorter. (I know I said the next newsletter was going to be Conway’s Law, that’s coming, but this one moved along faster…)

Better Know A Ruby Thing #3: Positional Arguments

Ruby has three ways to pass information from a method call to a method definition: positional arguments, keyword arguments, and block arguments. Each of these ways has: A syntax to declare an argument of that type in a method definition A syntax to declare an argument of that type in a method call A class that can can be used to convert arbitrary objects into and out of method calls A text marker that is associated with that kind of argument, *, **, or &.

Better Know A Ruby Thing Bonus: Contestants and Nesting

Sorry for skipping a week or two – I was approving copyedits on the book that is now called Programming Ruby 3.3, because we now want to be proactive about the next release. Coincidentally, the copyedit review does relate to this newsletter. I noticed a particular code sample as I was going through the book again, and it highlights a feature of Ruby’s constant lookup that I didn’t discuss last time.

Better Know A Ruby Thing #2: Constants

A fun thing about learning Ruby is that sometimes concepts that have the same name as in other languages have different behavior and purpose in Ruby. Today: constants They aren’t actually constant. They aren’t only used for small strings or magic literals. They aren’t even mostly used for that in most Ruby programs. Constants are one of the core pieces of Ruby and they aren’t super-well documented in the official site, so here we go…

Better Know A Ruby Thing #1: method_missing

Welcome to “Better Know A Ruby Thing”. In each one of these, we’re going to look at some feature of Ruby language, library, ecosystem, or culture and explain what it does, how it works, why it’s there, and any thing else that comes to mind. First up, method_missing. If I may be poetic for a second, method_missing represents both infinite potential, and the possibility of a second chance when you can’t figure out what to do the first time around.



Copyright 2024 Noel Rappin

All opinions and thoughts expressed or shared in this article or post are my own and are independent of and should not be attributed to my current employer, Chime Financial, Inc., or its subsidiaries.