DEV Community

Discussion on: Explain the 'super' keyword in ruby like I'm five

Collapse
 
imrawal profile image
Mee Lana • Edited

Is it good or bad to chain method in super like in below activerecord(5.1.6) code,

# 'delivery_timings' is a db field attribute
class Country < ApplicationRecord
  # expects array of times and converts to string ie. ['08:00-12:00', '14:00-16:00'] to "08:00-12:00,14:00-16:00"
  def delivery_timings=(val)
    return super(val) if val.blank?

    super(val.reject(&:blank?).join(','))
  end

  # converts string value to array of times ie. "08:00-12:00,14:00-16:00" to ['08:00-12:00', '14:00-16:00']
  def delivery_timings
    return super if super.blank?

    super.split(',')
  end
end

Although the code works, I'm smelling on code(may be wrong).