1. Список говнокодов пользователя maxk

    Всего: 4

  2. Ruby / Говнокод #22692

    −100

    1. 1
    2. 2
    3. 3
    4. 4
    (params[:date_lte].present? && params[:date_gte].present?) ?
            @events = CalendarEvent.where(:publication_date.gte => DateTime.parse(params[:date_gte]),
                                          :publication_date.lte => DateTime.parse(params[:date_lte]) + 23.hours + 59.minutes) :
            @events = CalendarEvent.order(publication_date: :desc).limit(6)

    Божественное использование тернарного оператора

    maxk, 28 Марта 2017

    Комментарии (3)
  3. Ruby / Говнокод #19836

    −55

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    before_create :build_client_info_attributes
    def build_client_info_attributes
      CLIENT_INFO_ATTRIBUTES.each do |attr|
        eval("def #{attr}();return read_attribute(:#{attr}).present? ? read_attribute(:#{attr}) : subject.try(:owner).try(:#{attr});end;")
       end
       eval("def country_id;read_attribute(:country).present? ? read_attribute(:country) : subject.try(:owner).try(:country).try(:id);end;")
    end

    Шедевр метапрограммирования.

    maxk, 18 Апреля 2016

    Комментарии (3)
  4. Ruby / Говнокод #19336

    −21

    1. 1
    (object.close? || object.rejected? ? false : (object.update_time.nil? ? true : (Time.now - object.update_time) >= 1.day)) && scope.try(:profile_client) == object.owner

    Условие - уровень "Бог"

    maxk, 20 Января 2016

    Комментарии (6)
  5. Ruby / Говнокод #19229

    −30

    1. 1
    2. 2
    3. 3
    4. 4
    def generate_activation_code(size = 6)
      charset = %w{0 1 2 3 4 5 6 7 8 9}
      (0...size).map{ charset.to_a[rand(charset.size)] }.join
    end

    Генерация кода

    maxk, 24 Декабря 2015

    Комментарии (0)