【发布时间】:2012-05-04 02:38:04
【问题描述】:
当然枚举在 Ruby 中不存在,但基于this post,我使用了类似以下内容:
class PostType
Page = 1,
Post = 2
end
我想将值传递给方法并使用它进行比较。所以:
initialize(post_type)
if post_type = PostType::Page
# do something here
elsif post_type = PostType::Post
# do something else here
end
end
但这不起作用,无论我将什么传递给我的类的构造函数,它总是产生相同的结果。
关于为什么将“假枚举”传递给方法并尝试比较它不起作用的任何想法?我必须比较价值吗?即post_type = 2?
【问题讨论】:
标签: ruby