Hi there,
it’s important to point out that you’re making a lot of use of standard Ruby - and whilst that may work, it’s not supported and may not work in future versions. The official line is that only the code in the tutorial is supported. However, if you’re happy with that caveat, feel free to use whatever works.