Created
January 12, 2018 12:58
-
-
Save JudeOstorn/d8e2fac730915d0d7662718086635702 to your computer and use it in GitHub Desktop.
ror_test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SuperEngine | |
# время поджимало вот что в голову пришло. дайте совет сделаю по другому | |
def max_speed(_a) | |
150 | |
end | |
end | |
class Car | |
include SuperEngine | |
def max_speed(super_info: false) | |
!super_info ? 90 : super | |
end | |
end | |
puts Car.new.max_speed # -> 90 | |
# как с помощью модуля переопределить метод класса, чтобы результат был такой: | |
puts Car.new.max_speed(super_info: true) # -> 150 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
# что бы вы изменили в этом коде? | |
class Note < ActiveRecord::Base | |
def created_in_future? | |
created_at >= Time.now | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# please refactor this | |
class UsersController < ApplicationController | |
def create | |
# тут длинная строка - не хватило времени решить как сделать её короче. | |
@user = User.build_from_omniauth(params[:user][:omniauth]) if params[:user][:omniauth].present? | |
@user ||= User.create(user_params) | |
after_create if @user.valid? | |
redirect_to new_user_path | |
end | |
def after_create | |
UserMailer.welcome_mail(@user).deliver | |
redirect_to root_path | |
end | |
private | |
def user_params | |
params.require(:user).permit(:email, :password, | |
:password_confirmation, :name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment