Skip to main content

Can Anyone explain me these ruby codes?

Rails • Asked by aysha

Recently I am started learning ruby on rails. I am doing a project on ruby on rails. In my project there are some code in application.controller.rb . But I am not understanding the meaning of the code. Can anyone please explain me these codes?

def new_year_holidays?
    t = Time.now

    @notification = t >= Rails.application.config.new_year_holidays_start_at &&
                    t <= Rails.application.config.new_year_holidays_finish_at
    start_date = Rails.application.config.new_year_holidays_start_at 
    end_date   = Rails.application.config.new_year_holidays_finish_at
    @new_year_holidays_start_at = start_date.strftime("%Y年%m月%d日(#{%w(日 月 火 水 木 金 土)[start_date.wday]})")
    @new_year_holidays_finish_at = end_date.strftime("%Y年%m月%d日(#{%w(日 月 火 水 木 金 土)[end_date.wday]})")
  end

This code is pretty dirty. Basically the @notification instance variable gets set to true or false if the notification is due. It also sets to other instance vars for formatting reasons but it's not a great way coding this. Somewhere else those instance vars used to check if notification should be sent and to show the formatted dates. If you just started learning make sure you find nice materials to learn from. This is definitely not one of those.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.