Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

似たようなメソッドの定義 #74

Open
kzytateishi opened this issue Jul 27, 2013 · 1 comment
Open

似たようなメソッドの定義 #74

kzytateishi opened this issue Jul 27, 2013 · 1 comment

Comments

@kzytateishi
Copy link
Contributor

似たようなメソッドを増やしていくのはどうなの...?

def fax?
  self.code == "fax"
end

def tel?
  self.code == "tel"
end

こっちの方がいい?

# fax?  tel?
self.pluck(:code).each do |code|
  define_method("#{code}?") do
    self.code == code
  end
end
@ohta-rh
Copy link
Contributor

ohta-rh commented Jul 27, 2013

基本的ににた様なメソッドは動的に定義することを推奨する。

ただし、定義されるメソッドは必ずコメントで書く事。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants