1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsで制御結合、スタンプ結合、データ結合、メッセージ結合

Last updated at Posted at 2019-12-22

# 制御結合
# @param  [User] user
# @param  [Bool] active_flg
# @return [Hash]
def shape_user_info(user, active_flg)
  # @type [Hash] user_info
  if active_flg
    user_info = user_info(user)
  else
    user_info = default_user_info
  end
  user_info
end

# スタンプ結合
# @param  [User] user
# @return [Hash]
def user_info(user)
  # @type [String]
  first_name = user.first_name
  # @type [String]
  last_name  = user.last_name
  # @type [String]
  fullname   = fullname(first_name, last_name)
  # @type [Integer]
  age        = user.age
  # @type [String]
  mail       = user.mail
  {
    fullname: fullname,
    age:      age,
    mail:     mail
  }
end

# データ結合
# @param  [String] first_name
# @param  [String] last_name
# @return [String]
def fullname(first_name, last_name)
  first_name + last_name
end

# メッセージ結合
# @return [Hash]
def default_user_info
  {
    fullname: "fullname",
    age:      30,
    mail:     "mail"
  }
end

間違ってたらごめんなさい🙃

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?