ruby 相关:http://weblog.jamisbuck.org/2015/11/14/little-things-refactoring-with-hashes.html

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 相关:http://weblog.jamisbuck.org/2015/11/14/little-things-refactoring-with-hashes.html相关的知识,希望对你有一定的参考价值。

# Other syntax without patch
STUDENT_LEVELS = {
  freshman:  Student::Underclassman,
  sophomore: Student::Underclassman,
  junior:    Student::Upperclassman,
  senior:    Student::Upperclassman,
  graduate:  Student::Graduate
}.tap { |h| h.default = Student::Unregistered }


# Other syntax with patch on Hash
class Hash
  def with_default(value)
    self.default = value
    self
  end
end

STUDENT_LEVELS = {
  freshman:    Student::Underclassman,
  sophomore:   Student::Underclassman,
  junior:      Student::Upperclassman,
  senior:      Student::Upperclassman,
  graduate:    Student::Graduate
}.with_default(Student::Unregistered)

以上是关于ruby 相关:http://weblog.jamisbuck.org/2015/11/14/little-things-refactoring-with-hashes.html的主要内容,如果未能解决你的问题,请参考以下文章

ruby 相关:http://weblog.jamisbuck.org/2015/11/14/little-things-refactoring-with-hashes.html

如何使用 Ruby 构建 HTTP 请求并将其发送到 Tor 隐藏服务

Ruby on Rails 学习之路

Windows下如何实现Ruby操作MongoDB(环境安装配置)

尝试访问我的 ruby​​ 项目-与 mysql 相关的 LoadError

与导出和返回值相关的 ruby​​ win32api 问题