Summarized using AI

Weird Ruby

Bozhidar Batsov • May 31, 2024 • Verona, Italy • Talk

In the presentation titled "Weird Ruby," Bozhidar Batsov explores the quirky characteristics of the Ruby programming language, emphasizing that its peculiar features are not necessarily negative but simply distinct. Batsov, a senior director of engineering at Toptal, shares his affection for Ruby while discussing its unique capabilities that have developed over its 31-year history. The presentation promises both fun and intrigue, aiming to highlight specific Ruby features that developers might find strange or useful.

Key points discussed include:

- Definition of Weird: Batsov begins by defining "weird" as something unusual or strange, contrasting it with Ruby's elegance and simplicity.

- Popular Weird Features: The presentation identifies several features considered weird, such as:

- Monkey Patching: The ability to modify existing classes in Ruby dynamically.

- Open Classes: Classes in Ruby can always be modified and extended.

- Blocks, Procs, and Lambdas: Handling of closures and return behavior can be complex.

- Method Missing: A powerful dynamic method that allows the handling of calls to methods that are not defined.

- Flexible Syntax: Ruby's interpretation of syntax can lead to unexpected results.

- Implicit Returns: Some Ruby expressions can return values without an explicit return statement.

  • Fun Examples: Batsov illustrates his points with various code snippets and examples, such as the peculiarities of adding and modifying strings and the behavior of iterators in unexpected contexts.
  • Cultural References: Throughout the talk, he includes relatable anecdotes and references to Italian culture, enhancing engagement while grounding some of the concepts discussed in familiar experiences.

The presentation culminates in a reminder to keep Ruby weird and to embrace its unique properties that contribute to both its charm and its challenges. Batsov concludes on a light-hearted note, emphasizing that while features may seem strange, they can enhance creativity and flexibility in coding.

The session is designed to not only inform Ruby developers of the language's quirks but also entertain them, making them appreciate the nuances of working with Ruby in both professional and creative contexts.

Weird Ruby
Bozhidar Batsov • May 31, 2024 • Verona, Italy • Talk

Over its long history (31 years and counting) Ruby has accumulated dozens of little known, obscure and somewhat weird features. Some of them are annoying, some of them are fun and a few are actually quite useful. In this session we'll go over some of my favorite weird Ruby features and we'll discuss how to make the best use of them (provided they are any useful, that is). It will be weird and fun, I promise!

Bozhidar Batsov is Senior Director of Engineering @ Toptal.

---

rubyday 2024 is the 11th edition of the Italian Ruby conference, organized by GrUSP,
The event is international, and all sessions will be in English.
📍 Verona | 📅 May 21, 2024

Join the next edition
🔗 www.rubyday.it

---

rubyday is organized by GrUSP.
We organize events, conferences and informal meetings involving Italian and international professionals.
We aim to make the ecosystem of the Italian world of web development better both in terms of skills and opportunities by creating greater awareness through comparison and sharing.

Subscribe to our newsletter:
✉️ [www.grusp.org/en/newsletter](http://www.grusp.org/en/newsletter)

 Follow us
 Website https://www.grusp.org/en/
 LinkedIn https://www.linkedin.com/company/grusp
 Twitter https://twitter.com/grusp
 Instagram https://www.instagram.com/grusp_
 Facebook https://www.facebook.com/GrUSP

rubyday 2024

00:00:00.320 morning everybody it is a great pleasure to be here and I think uh it is also a great responsibility to be the first
00:00:06.720 speaker because it means I have been entrusted uh so much responsibility by the organizers they must believe I'm the
00:00:13.480 type of person who actually prepares their talks in advance instead of on the day of the conference and they must
00:00:19.840 believe I'm the type of person who in Italy will actually practice their talk instead of drinking Quine um graa and uh
00:00:29.320 Amaro entire night so who
00:00:48.680 knows I have uh recently noticed that uh I bring a lot of luck to Italian sports
00:00:55.039 teams because just before I came to Verona I was spending a few days in bergam
00:01:00.519 and bum they finally wanton something after waiting from uh since
00:01:06.960 1965 so just saying and earlier in this year I went to
00:01:13.200 Milano 20 um so you know if uh if your Club is
00:01:20.119 struggling and it's not salana I can probably help so this is my third time here um
00:01:28.119 some memories from uh from the first event uh where luuka was actually here
00:01:34.000 and uh I was the type of person drinking Grappa the entire night still I had some
00:01:40.040 presentation um I was here last year where we had a lot of fun with some uh
00:01:46.840 fun people from Slovenia who unfortunately didn't survive and they're not here with us
00:01:53.399 anymore uh last year I I stayed in Verona for a while I discovered uh some
00:02:00.799 interesting coins some nice sites and um this year because I'm a big
00:02:08.360 believer that third time is the charm I think that the best is yet to come maybe
00:02:14.400 later tonight who knows so uh Monica said that I don't need an introduction but because I
00:02:21.239 wasn't sure I do have some self- introduction so that's my name written in cik for your convenience because I
00:02:28.519 know that our letters are so easy to read I know that nobody can pronounce my name uh so you can think of me as Buck
00:02:35.440 or Bojo which is how I'm typically code by my friends the first time thing
00:02:40.480 before I became a software engineer so um yes I have a hand online kind of
00:02:47.080 boring and more importantly today I have a proper haircut because normally I look like this but um yesterday I uh I fixed
00:02:57.560 my hair I shaved because I I really need a new profile picture this one is from a
00:03:03.319 conference I attended in 2019 so you know if somebody manages to
00:03:08.360 snap a good picture you know where to send it what has changed since like uh
00:03:14.680 last year I am older okay I am supposedly wiser or not
00:03:22.440 really because if I were really wiser I'd probably not have bothered to watch uh 5 hours of Rebel Moon just before
00:03:29.840 coming here or to attempt to reread the Wheel of Time which is just as bad as it
00:03:35.400 was when I was 20 so still I got stuck on book 10 this is horrible what's not
00:03:42.280 horrible is this if my talk sucks it's either because of Fallout or
00:03:50.200 because of the show that I watch to study Italian culture and Italian
00:03:55.599 language just before the conference so do you know what this is
00:04:01.000 no yes okay it's repley also known as The Talented Mr repley the end um um
00:04:10.000 adaptation of the famous book which takes place in Italy in uh in atan in
00:04:16.479 Venetia in uh in Roma uh it's pretty cool and uh I learned a few new things I
00:04:23.560 learned that if you go to atran or I guess half in Italy the word that you
00:04:29.120 need to know is Su and you have to use it
00:04:34.400 like but uh I also learned about Jun and I was thinking in Bulgaria we have this
00:04:41.240 famous shavara called suu so now I will never forget about those
00:04:47.440 words I also learned that the Italian police never asks about pictures of how
00:04:53.039 people look because they they managed to confuse those people for 10 hours which
00:04:58.520 was really funny and also the same inspector met one guy twice and he
00:05:04.639 believed he was two different people because of lauche uh this was so funny too
00:05:11.919 many spoilers but you still have to watch it what hasn't changed uh I still love
00:05:19.160 wine Italian wine is great although I had pictures just of German wine so
00:05:24.240 please do not kill me I still I still love watches uh even
00:05:29.720 more than last year and Tiny O's don't ask I don't know the so this is a
00:05:36.440 picture from my Instagram so this is actually what Instagram believes I'm going to like so they're like 70% right
00:05:44.880 I'm so crazy when it comes to watches that uh I start watching Apocalypse Now
00:05:49.919 I'm like hm Martin Sheen has a really nice Sao
00:05:55.639 6105 and Colonel Curts has uh first edition Rolex uh GMT Master the
00:06:03.759 filmmakers must have really taught long and heart uh to oppose the Japanese
00:06:09.720 culture the Japanese approach to building stuff to the Western I know it's boring right now but I'm get going
00:06:16.520 somewhere I hope maybe I'm going nowhere um so um why is this relevant today well
00:06:23.680 Seiko is made in Japan and um Ruby is made in Japan so I
00:06:29.840 was making some experiments with watches buying random watches putting them on my wrist and testing my productivity and uh
00:06:37.560 knowledge of Ruby I scientifically concluded that uh when I wear this watch
00:06:43.000 which I actually got from Italy my performance is 20%
00:06:48.160 better and when I'm wearing any of my casos my performance is 50% better and
00:06:54.319 the effects actually stuck so I can put one here and one here uh for this present
00:07:00.160 I'm wearing my beloved G-Shock so I think I will be a better programmer than
00:07:05.280 average I also see that um if you're in tasio you're a fun person to be around
00:07:12.039 but you'll tell me later today and I also noticed that uh if uh you're into
00:07:18.000 panise you're truly a douchebag uh so more about watches
00:07:24.720 before you kick me out I know that panai is the most famous Italian Watch brand
00:07:30.080 and I was really amused that this supposedly was a military issued watch which doesn't have minute markers so I
00:07:37.120 was really wondering uh how punctual the Italian Army is but um oh well I was
00:07:45.639 also really amused by the marketing campaign of the famous milanes company uh which I forgot the name
00:07:53.720 uh yalian what are those watches unimatic yes I remembered that
00:08:01.240 somebody really has to translate all those signs to me because I don't understand those advertisements and I
00:08:06.800 heard that they were really funny anyways there is just one person in the entire rubby community that cares about
00:08:12.840 this and he's not here with us today so let's switch to talking about open
00:08:18.479 source so I hope this is something that I'll do better with so yeah I do some
00:08:24.599 open source work probably in the Ruby Community I'm most known for the work I've done on the and trails Community
00:08:30.520 style guides and one really hated uh uh to uh in um in one uh um interesting
00:08:40.240 survey it was voted as the most loved and most hated to in the Ruby Community
00:08:45.800 I think rarely some two wins them both so I must be doing something
00:08:50.839 unique uh I I wanted to share a few small updates about rubocop before uh
00:08:57.440 before moving forward with we TR the topic of today's presentation first
00:09:03.000 rubocop um as of a few weeks supports the new super uh super optimized super
00:09:10.320 fast prison parser which in practice means that rubocop is even faster and yes it's a great success on a
00:09:19.800 personal note uh rubocop turned uh 12 years on April the 21st so just one
00:09:26.560 month ago I think this was a really nice Milestone because I think that um in
00:09:33.240 software every year is like 10 years so uh rocop is has really outlift all of my
00:09:42.079 expectations and this is another great success um fun trivia uh as of this
00:09:49.959 morning 5:30 a.m. RoboCop has 424 million downloads which is exactly 13
00:09:57.160 million downloads since my last present station last month ago uh interesting
00:10:03.320 data that it's probably boring but uh what's um funny is that in the alltime
00:10:10.880 uh list of most downloaded packages RoboCop is currently at number
00:10:16.519 68 and uh I see Rainbow and as and try
00:10:22.839 progress bar on this list which I have almost the same downloads can anybody guess why
00:10:33.440 those are three of rubocop dependencies so this is the this is the best way to climb up the
00:10:40.040 charts um and uh yeah that's all about rocop I cut a small release earlier this
00:10:45.839 morning to celebrate Ruby day in Verona um which probably fixed some bugs try it
00:10:51.440 out now it's time to talk about weird Ruby so getting down to business
00:11:00.040 when uh when I speak about weird stuff I always start with dictionary definitions
00:11:05.800 because I'm a weird guy so what is the dictionary definition of weird weird is
00:11:12.600 something of strange or extraordinary character or something relating to or
00:11:18.279 caused by witchcraft or the supernatural okay I
00:11:23.920 think I need more dictionary definitions another dictionary claims that we are is
00:11:29.600 something that is very strange and unusual unexpected and not
00:11:36.000 natural okay I can work with this and uh according to Ruby's own website Ruby is
00:11:42.320 a dynamic open-source programming language with a focus on Simplicity and productivity it has an elegant syntax
00:11:49.839 that is natural to read and easy to write okay so here it
00:11:56.240 was Supernatural not natural and here it's natural so
00:12:03.680 something must be wrong uh but uh before we dive into the
00:12:08.839 actual examples uh which will be plenty and mostly meaningless I want to clarify
00:12:14.480 that something being weird is not the same as something being bad and weird is
00:12:19.680 very subjective because we live in the era of AI I wanted to cheat a little bit with
00:12:26.839 my presentation because I told you I watched a lot of TV shows and I didn't
00:12:31.959 have much time so I asked Chad GPT what are the top 10 most weird features of
00:12:38.639 the Ruby programming language and this is what I got uh verbatim I haven't
00:12:43.680 edited it all feature number one monkey patching okay feature number two open
00:12:51.720 classes okay this was kind of surprising but um I can uh I can
00:12:59.560 understand where this is coming from feature number four blocks procs and lambdas okay five method missing is
00:13:10.000 apparently very weird for chat GPT I it gets better trust me meta
00:13:15.760 programming what was almost everything before this chat GPT I thought you were
00:13:20.959 smarter than this here is my favorite part flexible syntax and this is the
00:13:26.959 example that chat GPT gave me about the flexibility of the Ruby syntax okay gets
00:13:35.360 better implicit returns one of the most weird features in
00:13:48.279 myself self context changes uh I before seeing the example I wasn't quite
00:13:54.120 certain what the title meant to be honest um you tell me feature 10 keyword
00:14:00.880 arguments with default values okay so this is how I felt after
00:14:06.920 this interaction with um Chad GPT but my job is done it was a great pleasure to
00:14:13.199 be
00:14:19.320 here I think it's safe to say that we are not going to be losing our jobs to chat GPT anytime soon and uh maybe there
00:14:27.759 is still some usefulness in a human providing you their opinion
00:14:32.839 on what is weird about Ruby so bonus SLS uh 110 of them Ruby is as of today 31
00:14:42.519 years old so that's 3 10 years uh in uh in human years almost as old as Verona I
00:14:49.880 guess and uh what the great Ruby programmer The Joker has told us applies
00:14:55.639 fully to Ruby if something doesn't kill you it simply makes you weirder which
00:15:00.959 means that probably Ruby is a very weird language and because um weirdness is
00:15:08.440 hard to quantify I uh decided that we are have going to have something um special today
00:15:16.040 I'm going to be showing you some things that I believe are weird as uh a ruby
00:15:22.079 developer with some questionable experience who has seen seen a lot of strange code in the issue Cho a fope um
00:15:31.519 so uh the first level is going to be the most familiar one
00:15:37.399 what and uh we are going to visually illustrate it like this and because
00:15:43.079 we're in Italy and I told you I learned a lot from replay today what is going to
00:15:49.680 be mostly mamame Mia uh and
00:15:54.839 occasionally masero I hope I'm doing this right if I'm not blame
00:16:02.519 Monica uh the next level of weirdness which I have cleared with the
00:16:07.959 code of conduct is going to be this and uh I received some feedback uh last
00:16:15.759 evening from a person who saw me speak in Bulgaria and bulgarians are known for
00:16:21.120 their very expressive and explicit language and they told me that they counted me saying um 15 times uh on
00:16:28.959 my last talk and uh so many times that uh they couldn't count it uh so I
00:16:35.920 decided to try something new today I consulted two of my best Italian friends Davida and Monica and they told me what
00:16:43.759 to say instead of and if I'm saying something right Monica taught me
00:16:49.519 this if I'm saying something wrong David did it because he's not here so
00:16:55.680 um uh they told me that uh I could go with mad or um I could go with the more
00:17:03.880 poetic kakatua or the even more poetic
00:17:11.240 Kat or the even more poetic Kat I'm a little bit confused uh but uh
00:17:19.360 I I feel uh I feel they uh they can be applied to the right piece of coat as
00:17:24.679 you're going to see later and the final level um it happens uh rather
00:17:30.760 infrequently the final level of weirdness in English is usually described as holy but in uh Italian
00:17:39.200 it can be described in only one way
00:17:44.919 Madonna so let's start there are going to be some code samples I promise Monica
00:17:50.400 said that we are going back to the basics and we are really going to speak about trby today so first we are going
00:17:56.400 to speak with about some um things that are weird but I think almost
00:18:01.600 everybody knows them I call them the usual suspect suspects and we are doing this just for the sake of calibrating
00:18:09.240 the weirdness levels so I can ask you some fun questions down the road
00:18:14.520 so um everybody probably has seen um end and begin blocks which allow you to
00:18:20.280 reorder the flow of execution of an application something that you should never do in a real application but
00:18:27.200 exists to be shown on present like today so this is uh mam Mia
00:18:33.679 level uh then we have U uh flipflops another feature that exists but I've
00:18:40.440 never seen other than on Ruby presentations mam
00:18:46.440 Mia then we have uh begin and comments which are something that exists and I've
00:18:52.360 rarely seen even on presentations but it's there and it's useful on days like
00:18:57.400 this why are those weird because they must be placed at the very beginning of a line to work so this uh one compile
00:19:07.039 it's broken which
00:19:15.360 is I expected more so pay attention uh pay attention everybody
00:19:22.200 okay and to work it has to be actually indented like this which is
00:19:34.760 okay let's try this the there is um one Legacy syntax
00:19:42.840 uh for single character litos that uh you should never use but it is there and
00:19:50.720 it is Mama Mia ah and it gets even weirder because
00:19:58.159 you can use this syntax to express things like control characters like this
00:20:03.200 is control a this is control old F I don't know why anybody would want to do
00:20:09.720 it but it is possible in Ruby and this
00:20:17.240 is oh yeah uh you're getting the H of it uh I I think you needed more coffee you
00:20:24.440 needed more coffee okay we're continuing the calibration
00:20:31.320 exercise re assignable contact constants just uh the heading here should be
00:20:37.120 giving you a hint where we are going but in Ruby we have constants which are
00:20:42.159 supposed to be constant but you can reassign them and all you get is a warning and this can be just one just
00:20:51.080 one thing let's say all together now
00:20:56.880 madon okay okay okay making progress we're getting better and better
00:21:03.919 class variables everybody knows about them nobody uses them because they are
00:21:09.720 really messed up in a serious of ways most notably uh you can change the same
00:21:16.880 class variable from multiple classes in the class hierarchy uh normally you would be
00:21:22.200 advised not to do that because this is a mamame Mia type of feature uh and the side note Ruby 3
00:21:29.840 actually changed this Behavior a little bit so if you do something extra crazy
00:21:35.360 at least you are going to get a runtime error this time around so this is a nice Improvement that I learned about
00:21:42.200 recently from a rubocop isue this is how I learn everything about Ruby people are
00:21:48.039 complaining and are sending me some code that I never thought anybody would write and uh I tag it with weird trby
00:21:56.760 and they save items for this present presentation now that we are properly calibrated the real presentation begins
00:22:03.960 we have only 85 slides of weirdness uh ahead of us um okay so this looks simple
00:22:12.600 right um uh can somebody tell me what is going to be the output from this Cod
00:22:21.159 snippet okay the it is uh it is going to be true because uh because of the
00:22:28.559 precedence rules in Ruby this expression is essentially the same as this one and when you have true or something it's
00:22:36.320 true uh this is the same expression with um um or and end written
00:22:43.919 differently uh what is going to be the output here and
00:22:50.240 uh but it is the same operators uh why is it different oh because in a weird um
00:22:58.679 stroke of Genius or not so much uh or and end don't have the same precedence
00:23:05.480 as the other version of or inent and actually they have the same so uh if you
00:23:11.400 uh add the explicit Association it looks like this and the result is false which
00:23:17.320 can be only okay I like you
00:23:24.240 now getting better and better I hope all of you are familiar
00:23:29.640 with this uh special n object in Ruby which is essentially a hash where you
00:23:36.919 can access um all the shell environment in which your application is running but
00:23:44.279 uh if you check the class of uh this n object you might be in for a little
00:23:51.480 surprise who can tell me what is the class of n
00:23:59.520 yes a class is object and uh why is it object does anybody have any
00:24:06.640 idea well anything is an object but this is a special object um it's not a hush because um
00:24:14.520 when you assign values uh to this you are actually changing the environment
00:24:20.279 and when you read values from this it has to make sure that it is synced with the environment so it's not a snapshot
00:24:26.840 of the environment but is constantly sinking up with it and uh I don't know
00:24:33.080 about you but for me this was one of the KATU moments in
00:24:39.640 life okay this is a simple one who can tell me what is this number on the
00:24:48.360 screen okay the gentleman over there guessed that the answer is 10 does
00:24:54.159 anybody know why the answer is 10 uh which uh Prov such reactions in many
00:25:03.799 people okay uh it is 10 because this uh everything that is starting with every
00:25:09.080 numeric literal that is starting with zero uh is actually treated as an octal
00:25:14.600 number by Ruby go figure and this is actually a short hand for the most more explicit um octal syntax where you
00:25:22.679 actually have the letter o in the literal you probably know that uh Ruby also has
00:25:28.880 literal Syntax for binary numbers and for hex numbers I never needed them for
00:25:35.039 anything except for code goink and we are through be presentations but they're there if they need them if you need them
00:25:42.399 okay something very simple is this bit of code going to compile or
00:25:51.640 not yes no let's see shout yes if you believe this is going to compile
00:25:58.000 together shout no if you believe it's not going to
00:26:03.799 compile okay most people believe it's going to compile and they are
00:26:09.279 right another weird try is this going to
00:26:14.880 compile shout shout uh people are
00:26:22.520 divided it's not going to compile and uh why is this uh because there is a
00:26:27.960 special handling for um um modifier for
00:26:33.279 modifiers like if unless if um if they're appended to a numeric literal um
00:26:41.279 the parer can unambiguously tell that we are dealing with two identifiers one
00:26:47.600 that is the literal and one that is the key word but now it can't uh I have no
00:26:53.360 idea who thought that uh this special case was a good idea but it's there and
00:26:59.200 it allows you to write beautiful askart uh in Japan this is something
00:27:04.399 that is very famous so okay oh everybody
00:27:09.960 knows that this is the way to increment a numeric variable in Ruby
00:27:16.240 right at uh is this valid Ruby code and is this Val TR code
00:27:30.240 K it's valid it's valid and uh it's valid for a very simple reason this is
00:27:36.840 just a lot of sted um un operators so in essence Plus+ plus X would just be X and
00:27:46.279 this example makes me feel like a member of the X-Men by the way on the topic of x uh
00:27:53.039 since last year I'm on a new Social Network CeX
00:27:58.320 and because it's uh katso I'm also on Blue Sky and on
00:28:04.480 Mastodon and uh I'm very unhappy because I missed the days where everybody was on the same social network and it was
00:28:12.760 nice okay are you ready for the next level we
00:28:17.960 were just warming up object oriented negation so I've noticed that many
00:28:24.120 people believe that negation in Ruby is some special keyword but in reality it's
00:28:30.480 not it's just a method that's called um exclamation mark so you know if you're
00:28:37.200 inclined inclined to you can write code like this which for me was one of those
00:28:42.519 Mama Mia moments in life but um I realized uh recently that you can push
00:28:49.279 this further uh I told you that uh Ruby is very expressive allows you to write
00:28:54.880 naturally looking code so I thought of something brilliant which actually
00:29:00.240 extremely dumb never do it at home I could Define um one famous uh
00:29:07.880 mathematical operator in the integer class and now I can write this beautiful
00:29:14.120 beautiful code U that uh you should never
00:29:19.919 do uh this is factorial I hope everybody understands this um okay more interesting um uh and
00:29:30.720 slightly weird things about Ruby did you know you could increment strings in Ruby
00:29:36.799 the way you increment numbers like Ruby has this uh suck method that doesn't
00:29:42.600 suck but rather succeeds uh it gives you the natural successor of something in the case of a
00:29:49.440 number that's the next number and this is useful in ranges to be able to generate a sequence of successive
00:29:56.840 objects but but um it's a little known fact that this is also defined for
00:30:01.960 Strings and it allows you to write code like this and you notice that uh actually it has some interesting special
00:30:08.919 handling uh for example uh example the case
00:30:14.679 1,999 uh zzz uh it looks very smart in what is
00:30:20.440 doing it and later special handling of Science and um mder
00:30:28.640 um so I know what you're thinking right now I'm going to use this feature to
00:30:34.159 write a version generator you know you have this strange of ver versions uh
00:30:39.960 what can go wrong well it turns out that a lot of things can go wrong uh the
00:30:45.039 first small example is promising but the second one when you want to get the
00:30:50.279 versions from 1.0 to 1.10 gives you like uh 1,000
00:30:56.000 versions um which is not uh what you expect and yeah this is
00:31:02.440 how I felt uh when I learned
00:31:08.679 this okay uh this gets even weirder when you pair it with my native Bulgarian
00:31:16.679 language but I have a feeling I'm what one of three people in the audience who can understand those examples so I'll
00:31:24.159 just uh skime over them more about strings did you know that
00:31:31.200 strings can be positive negative or neutral I learned about this recently in
00:31:38.760 a rubocop is show when somebody told me that this wasn't working I responded I
00:31:44.519 think your code is broken but um it turned out that you can actually put um
00:31:50.039 a plus in front of a string and uh as weird as this might look it actually
00:31:56.240 does something useful when you're using the Frozen string literal directive this
00:32:02.000 is giving you a copy of the string that is UN Frozen so you can actually modify
00:32:07.279 it and you can do the absolute same thing in Reverse if a string isn't Frozen prefix it with minus this is
00:32:14.080 going to make it frozen yeah I feel like I should think now but I probably
00:32:20.639 shouldn't uh okay more weird stuff but simple a couple of uh highly
00:32:29.080 consistent predicates in Ruby so is z 0 true is z non zero NE is one zero false
00:32:37.919 is one non zero
00:32:43.480 one Mama Mia to infinity and beyond uh let's
00:32:50.279 check some infinite predicates which uh I think are even funnier is one
00:32:56.600 finite yes true is one infinite new
00:33:03.320 okay is infinity finite force is infinity infinite
00:33:12.919 one
00:33:18.080 madon my favorite part of the presentation here dos so most of you I
00:33:24.799 hope know that here dogs by default behave as double quoted U string
00:33:30.320 literals meaning you can interpolate stuff in them so if you put into this
00:33:37.000 string Mordor you're going to get the opening of The Lord of the Rings give or
00:33:42.399 take uh but uh have you thought uh how do you achieve the effect of single
00:33:48.440 quoted uh literals I think you'll find uh the syntax kind of weird because you
00:33:55.679 have to quote only the opening lier and um it gets better from here if you do
00:34:02.399 this okay you have a single quoted delimiter but you can now have spaces in
00:34:08.639 the delimiters and you can get really really wild actually you can have
00:34:14.359 delimiters like this one here and this is going to
00:34:23.320 compile M uh it gets even better I recently
00:34:29.720 learned from a rubocop issue that you can Nest here docks I don't know why anybody would
00:34:37.599 ever want to do it but it looks like this it took me a while to process this
00:34:42.800 syntax um and this is the output
00:34:49.240 um yes that's the only appropriate
00:34:54.879 reaction do you know how many ways there to invoke lambdas in Ruby any
00:35:01.200 guesses shout um raise your hands if you believe
00:35:06.320 it's one nobody two
00:35:12.040 3 4 five huh okay let's count so we have a
00:35:20.560 Lambda we have a Lambda and we can call it most conventionally like this
00:35:28.200 in modern times like this if we want to appear fancy and
00:35:34.839 knowledgeable we can do it like this if we want to be uh wearing pan
00:35:40.760 eyes we can do it like this so four but there is also one more way
00:35:48.240 which is butt madona level to do
00:35:55.480 it okay are you still with me is this the worst
00:36:01.400 talk you have attended in your lives okay so uh do you know which
00:36:08.079 method has the most aliases in the Ruby standard Library any
00:36:18.280 guesses I'll give you a hint it's in the hash
00:36:23.440 class key is close enough it's an acceptable answer the method was originally named
00:36:29.480 include at some point somebody added the member alas at some point somebody added
00:36:35.240 the key Alas and at some point somebody added the his key Alas and yes this
00:36:41.680 escalated quickly there are a few honorable mentions in Ruby methods uh
00:36:47.319 that have three names like uh Q pop Q deck and Q shift Q push Q ank and
00:36:55.000 Q I don't know and it's funny that the Q class has eight methods but six of them
00:37:01.359 are aliases I don't know about you but I
00:37:08.400 find it a little bit weird we are almost there 10 more slides
00:37:15.480 to go and almost on time impressive so
00:37:21.560 mixing coat and data a little known feature of Ruby is that uh if you add
00:37:28.640 something after the end identifier this is going to be textual data that is
00:37:36.079 going to be automatically bound to a data object so in the example um above
00:37:44.400 which which I know is kind of weird you are going to get this beautiful
00:37:53.119 output you're not impressed I have to do harder do you know know that uh Ruby is
00:37:59.240 so magical and Supernatural that you can make something out of nothing so new
00:38:05.000 typically stands for nothing right um but uh with the right methods you can
00:38:11.280 create a hash an array a string or a few numbers I'm not sure about you but I
00:38:18.440 don't believe that zero and N are the same thing and it gets even
00:38:23.760 weirder because with the safe conversion function you get errors in some cases and objects
00:38:31.880 in anothers talk about consistency you know some wise developers have said that
00:38:38.040 explicit is better than implicit errors should never pass silently in the fence
00:38:43.560 a face of ambiguity refuse the temptation to guess but this is the Zen of python and this is
00:38:51.240 Ruby keep Ruby weird my friends graia
Explore all talks recorded at rubyday 2024
+1