Hidden Partial Application in Ruby

It’s like coming home
valid_length?(raw) && only_digits?(raw) && valid_sum?(raw)

Rubyisms and PORO Elements

  • Class method to instance def self.method; new.method; end
  • Every Rubyist’s favorite i word: initialize
  • attr_reader
  • private methods
  • ? suffixes for predicate methods

Functional Elements

  • Composition/chaining in Luhn#luhn_sum
  • Lambdas -> combined with Enumerable methods map(&luhn_double)
  • Variable names of x 🙀. I’m cool with this because I am obviously doing math so the vars are obviously math-able values (aka numbers). In others words, I don’t think naming it value , number , or even int adds much more meaning/intent than x .
  • Declarative by default. The assumption is that future developers only need to know what Luhn#valid? does, not how it works. If the developer wants to understand the implementation, they are free to do so, but not required. It would be totally adequate to just look at the definition of Luhn#valid? to get a good enough understanding of what is going on.

Conclusion

--

--

--

Licensed Driver 🚗 TSA Pre ® AeroPress Barista ☕️ Conversational in Emoji 🤟 Anti-mouse (💻✚🏠) Pro-listening 👂he/him 👨‍💻 @TEDTalks

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

LeetCode 321: Create maximum number — a dynamic programming approach

5 ways to Python efficiency with NumPy

print(“Do you want fries with that?”)

Software Architect — I

ARTH_TASK 14…!!

How to Configure Background Jobs with Dotvvm

Why I Chose Software Development

Batch Transcription using Azure Speech Service

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mike Schutte

Mike Schutte

Licensed Driver 🚗 TSA Pre ® AeroPress Barista ☕️ Conversational in Emoji 🤟 Anti-mouse (💻✚🏠) Pro-listening 👂he/him 👨‍💻 @TEDTalks

More from Medium

How to Add JWT Auth API to Existing Rails Application

Server with wires

Creating Rails Api Using Existing MySql Database

CURD actions with Ruby Sinatra

Ruby on Rails error handling guide