SlideShare a Scribd company logo
My month with Ruby
Who is this guy?
- Alex Tomovski
- Backend Developer (primarily)
- Scala, Java, Groovy
- Recently crossed to the dark side… JS
How did I end up coding Ruby?
- Joined Wix in the summer.
- No project was waiting for me.
- Finally after two weeks I got a call…
How did the colleagues react when I
told them I’ll be doing Ruby?
Some of them got creative :)
What was I supposed to build?
- Thin Rest Wrapper
- But why?
- Make developers life easier.
- Annoying request signing logic
- Document and provide examples for the APIs
The API
Where do you start???
- Book: The Ruby Programming language
- IRB
- Setup the project
- Look at other examples/tools
- www.ruby-toolbox.com
Setting up the project
- Bundler and Rake
- Love at first sight (especially for bundler)
I want less of this: and more of this:
Hello World!
- Tests
- RSpec + Guard
- Tests run in the background
- Immediate feedback
- WIN!
Testing a dynamic language
- Paranoia!
- What happens if someone
passes the wrong type?
- Guard statements
everywhere?
- Wait do I care?
Integration (e2e) Tests
- Easier refactoring
- Faster bug discovery
- VCR
- https://github.com/vcr/vcr
- Records HTTP Interactions
- Fast re-execution
- Helps with debugging
VCR Cassette
First Impressions
- Easy to learn
- Readability
- Super FUN!
Guard Statements!
Mutability
- Hard to come back to it
- Side effects
- Freeze?
Blocks? Lambdas? Procs?
Vision
- One entry point (the client)
- Minimal configuration
- Optional extensive configuration
Structuring the gem
- Modules
- Mixins
REST Client VS. Faraday
- Ease of use
- Extensibility
- Plugable middleware
- Configuration
Faraday
Classes or Hashes?
- Response handling
Classes
- Easy data access
- Hard to create
Introducing Hashie
- Best of two worlds
- https://github.com/intridea/hashie
Hashie Example
Too much magic
- It was all great until this:
/hashie/dash.rb:41:in `block in property': wrong number of arguments (1 for 0)
(ArgumentError)
from /hashie-3.2.0/lib/hashie/hash.rb:48:in `flexibly_convert_to_hash'
from /hashie-3.2.0/lib/hashie/hash.rb:34:in `block in to_hash'
from /hashie-3.2.0/lib/hashie/hash.rb:20:in `each'
from /hashie-3.2.0/lib/hashie/hash.rb:20:in `to_hash'
from /hashie-3.2.0/lib/hashie/hash.rb:42:in `to_json'
A day latter…
Monkey Patching
And we’re Almost :) done
- Final thoughts:
- Threading
- Meta programming
- Would I use Ruby again?
Thank you!
Questions, Comments?
Repo: https://github.com/wix/wix-hive-ruby

More Related Content

PPTX
Real time web: is there a life without socket.io and node.js?
KEY
Building MapAttack
PDF
Infrastructure as code might be literally impossible part 2
KEY
Hybrid concurrency patterns
PDF
Node.js Patterns and Opinions
PDF
Node.js and Ruby
PDF
Cucumber.js: Cuke up your JavaScript!
ODP
Riereta Node.js session 3 (with notes)
Real time web: is there a life without socket.io and node.js?
Building MapAttack
Infrastructure as code might be literally impossible part 2
Hybrid concurrency patterns
Node.js Patterns and Opinions
Node.js and Ruby
Cucumber.js: Cuke up your JavaScript!
Riereta Node.js session 3 (with notes)

What's hot (20)

PDF
NodeJS ecosystem
PDF
PPTX
EhTrace -- RoP Hooks
PDF
Real-time Web Application with Socket.IO, Node.js, and Redis
PPT
Rust Programming Language
PPTX
Re-thinking Performance tuning with HTTP2
PDF
How to-node-core
PPTX
Node js for beginners
PDF
Virtualisation - Vagrant and Docker
PDF
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
PDF
Ruby is dying. What languages are cool now?
PPTX
T4T Training day - NodeJS
PPTX
Node js introduction
PDF
Nodejs and WebSockets
PDF
Crate Packaging Standalone Ruby Applications
PDF
(C)NodeJS
PDF
Building a REST API with Node.js and MongoDB
PDF
2019 PHP Serbia - Boosting your performance with Blackfire
PDF
NodePDX Slides
PDF
Node.js for Rubists
NodeJS ecosystem
EhTrace -- RoP Hooks
Real-time Web Application with Socket.IO, Node.js, and Redis
Rust Programming Language
Re-thinking Performance tuning with HTTP2
How to-node-core
Node js for beginners
Virtualisation - Vagrant and Docker
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
Ruby is dying. What languages are cool now?
T4T Training day - NodeJS
Node js introduction
Nodejs and WebSockets
Crate Packaging Standalone Ruby Applications
(C)NodeJS
Building a REST API with Node.js and MongoDB
2019 PHP Serbia - Boosting your performance with Blackfire
NodePDX Slides
Node.js for Rubists
Ad

Similar to My month with Ruby (20)

PPT
Rapid Application Development using Ruby on Rails
PPTX
Day 1 - Intro to Ruby
PPT
WorkinOnTheRailsRoad
PPT
Workin ontherailsroad
PDF
ruby pentest
PPTX
Why Ruby?
KEY
Ruby on Rails Training - Module 1
PDF
IJTC%202009%20JRuby
PDF
IJTC%202009%20JRuby
PDF
Ruby Best Practices Increase Your Productivity Write Better Code 1st Edition ...
KEY
Introduction to Ruby
PDF
Ruby tutorial
PDF
Ruby Presentation
PDF
Workin On The Rails Road
PDF
Ruby training day1
PDF
Ruby tutorial
PDF
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
ZIP
Meta Programming in Ruby - Code Camp 2010
PDF
Ruby Rails Overview
PPT
Ruby - The Hard Bits
Rapid Application Development using Ruby on Rails
Day 1 - Intro to Ruby
WorkinOnTheRailsRoad
Workin ontherailsroad
ruby pentest
Why Ruby?
Ruby on Rails Training - Module 1
IJTC%202009%20JRuby
IJTC%202009%20JRuby
Ruby Best Practices Increase Your Productivity Write Better Code 1st Edition ...
Introduction to Ruby
Ruby tutorial
Ruby Presentation
Workin On The Rails Road
Ruby training day1
Ruby tutorial
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
Meta Programming in Ruby - Code Camp 2010
Ruby Rails Overview
Ruby - The Hard Bits
Ad

Recently uploaded (20)

PPTX
Patient Appointment Booking in Odoo with online payment
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
Cost to Outsource Software Development in 2025
PDF
Autodesk AutoCAD Crack Free Download 2025
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Complete Guide to Website Development in Malaysia for SMEs
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Patient Appointment Booking in Odoo with online payment
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
17 Powerful Integrations Your Next-Gen MLM Software Needs
Cost to Outsource Software Development in 2025
Autodesk AutoCAD Crack Free Download 2025
Oracle Fusion HCM Cloud Demo for Beginners
Reimagine Home Health with the Power of Agentic AI​
wealthsignaloriginal-com-DS-text-... (1).pdf
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Monitoring Stack: Grafana, Loki & Promtail
Operating system designcfffgfgggggggvggggggggg
Download FL Studio Crack Latest version 2025 ?
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Design an Analysis of Algorithms II-SECS-1021-03
Computer Software and OS of computer science of grade 11.pptx
Complete Guide to Website Development in Malaysia for SMEs
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM

My month with Ruby

Editor's Notes

  • #7: Thin Rest Wrapper around a collection of API’s that Wix exposes to third party application developers.
  • #9: How do you choose tools when you have no experience and no one to ask? You use google :) and find ruby toolbox. This really helped me and almost all (I’ll talk about exceptions in a minute) of the tools that used are based on the stats from this place. IRB - Although scala has the repl and I always found it useful, what I loved about the IRB and found more convenient is the fact that you can simply require gems and play around with them.
  • #10: Coming from the world of Scala/Java where you need to choose between maven gradle or sbt for your project using bundler and rake was like a dream come true. And what I truly loved about them is the simplicity and the fact that the dependency management is separated from the tasks part! No more xmls or spaghetti code for dependencies, build ,package and test tasks.
  • #11: Guard running the tests. Amazing when coming from Scala!
  • #12: No compiler no types I need to test everything! During my first week this was the attitude that I had and I wrote a whole bunch of unit tests that had nothing to do with behaviour! But I quickly realised that I’m trying swim against the tide here. I heard/read various opinions on how you should write more unit tests when you are coding in a dynamic language but what I actually found the most useful are integration tests! But say you had a test that tested the system/component from the outside? Would that help? IMHO it might and it might help you catch bugs faster and thats why we need integration and e2e tests….
  • #13: As we spoke just a minute more often than not we need to refactor some bits of the system or in this case library. This will involve changing sometimes multiple components and although unit tests are great in this case they were not enough for me to feel comfortable making those changes. Also early in that one month I found myself creating bugs :) and these tests made sure to keep me in line. OK I realised I needed integration and end 2 end tests but I now had to add them to the project. What I wanted was: 1. Fast integration tests to run with guard. 2. E2E tests to exercise the library against a test app. After playing around a bit I realised that the tests in both cases are the same the only thing that was diferent is that I wanted the integration tests to run faster :) And as I already learned by now: There must be a GEM for it :) and there was VCR. Its an awesome tool basically it records the HTTP interactions and enables you to re-execute them in a fast manner locally while you are developing. Exactly what I needed. Another nice thing about VCR was that the interactions were saved as yaml files and were very readable so I found myself looking through them to resolve some issues both on the server and in the library iteslf. OK now that I had the tests set up it was time to actually write the gem…
  • #15: By this point I’ve already had a few weeks of coding in Ruby… The first impression that I had about the language was how easy it was to pick it up and how naturaly it was to write code in Ruby. The code that I would write was almost like english making it the most redable language I’ve had the pleasure to work with. Not everything is pink in Ruby land though :) Mutability was something that I had to get used to coming from Scala.
  • #19: Here is the outline of how I wanted the gem to look like: One entry point…. meaning I the client would have to know only about a single class and easily pull it in. Minimal configuration… again I wanted developers to be able to require the gem and be able to start using it in a matter of min without having to go through a ton of documentation. Optional extensive configuration… for more advanced clients I wanted them to be able to configure anything from logging to http timeouts to headers. With that in mind and having looked at a couple of examples :) I set out to write the gem.
  • #20: First thing that I loved about Ruby was the modules! Lets look at the example of the structure that I was able to give to my code. So lets start with the client it pulls in the Rest API. The rest api defines the different groups of apis that it has. And finally lets look at the first one. One thing that was hard to get used to is that you can call methods from the parent object but that again comes down to me not being used to the dynamic nature of the language :) Now that I had this walking skeleton in place it was time to actually make some http calls and make the first e2e test pass. ??similar to Scala traits they are similar in the sense that modules are mixins and mixins are traits that can have state.
  • #21: Although the title of the slide looks like there was some battle :) between the two. To be honest there was not after maybe a day playing around with the two these were the takeaways: REST Client is for sure easier to use… It has a simple interface BUT but you pay for that simplicity by the lack of extensibility. This was the thing that made up my mind about Faraday! My code was encapsulated in small “racks” that I pluged in and they did one very specific job! For example the error handling [show slide]. And also it fit nicely with my initial idea to expose a fair amount of configuration to the advanced end user.
  • #23: Once I had the the whole thing set up and got my first response back from the gem I was not very satisfied with the response… :) I got a hash back… this was not the usage I had in mind. How I actually wanted this gem to work is that the user would receive an object back that he can access. For example: [show example] So I started creating this kind of objects by hand and added some parsing logic to populate them it looked great until moment I actually wanted to send a request to create a contact for example… and that looked like this [show example] and this was also not what I wanted… and if that was not enough I realised that I also need some validation on the objects. And again before long I applied the most valuable lesson in Ruby that I’ve learned so far and that is: If you are doing something complicated stop there is a gem for it :D And there was Introducing hashie the best of two worlds [show example] with hashie I was able to give the flexibility for developers to choose their own style in which they read or create objects.
  • #27: I was making rapid progress with Hashie. Things were so easy :) I even took it a step further and generated some of the classes from a predefined json schema. Until I got this error. First things first this didnt tell me anything to be honest so I started debugging and after maybe a day or so I figured it out :) one of the responses that I was getting contained a field named method. And guess what hashie did when it found a field like that? Well it declared a method called method :) and kaboom you loose one of the base object methods. And its just a ticking bomb until this pops up somewhere on runtime.
  • #29: Lets start off with the fact that I had to solve my problem. It was too late to go back and do a reafctor on the library because of one “small” issue. So I resorted to I suppose everyone in this room has done once or twice in their Ruby career and that is Monkey Patching. I suppose you have read heard argued on this subject so I wont take too much of your time and I will break my view on it down to 3 simple points. Obviously the good part is that the language enabled me to go around an issue or to add functionality to a class where needed. This fits nicely with the OOP open closed principle. Well the bad thing here is that I can override or practically erase a behaviour of any class. Thus violating the “closed for modification” part of the open closed principle. Once you monkey patch for the first time it works like heroin :) you just want to do it more and every problem looks like a perfect fit for monkey patching. And if you are not carful you can endup with an ugly unmanageable code base. And although I lack the experience to speak about this in the Ruby world we have something very similar in Scala called implicits which is basically allows you to extend a class with new behaviour. But what happens usually when you learn implicits for the first time is that you use them everywhere you go crazy with them. And then good luck reading the code or debugging through it.