Skip to content

Comment on Class methods are Ruby's useEffect

Comments

The post says "Most of our Ruby code reads like English, but that’s not the case when we combine multiple DateTimeFns class methods", and to illustrate this, gives the following agreeably ugly example:

  DateTimeFns.add_minutes(DateTimeFns.add_hours(DateTime.current, 1), 1)
Sure thing, but the syntax can be improved without restorting to refactor into instance methods:
  DateTime.current.then {
   DateTimeFns.add_hours(_1, 1)
  }.then {
    DateTimeFns.add_minutes(_1, 1)
  }
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.