Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
耗子
@willmouse
VIP
NO. 717 / 2012-01-09

北京
46 Topics / 407 Replies
11 Followers
0 Following
29 Favorites
好身材的程序员都是好程序员...
GitHub Public Repos
  • symbolinenglish 57

    How to say ~!@#$%^*;"... in English, Chinese, Japanese and Spanish?

  • chsource 14

    Change Gemfile to use 3rd party sources quickly.

  • armory-recorder 3

    source code of wowarmory.me

  • vim-mac-classic-alt 3

    Vim port Textmate Mac Classic theme with improvements

  • emacs.d 2

    another emacs.d

  • weih.github.com 2

    source code of my jekyll site

  • vim-skittles-theme 1

    Vim Skittles theme

  • rails-passenger-cookbook 0

    Simple Chef cookbook for Rails app depolyed with phusion passenger

  • railsready 0

    Ruby and Rails setup script for Linux and OSX

  • emmet-mode 0

    emmet's support for emacs.

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 有带智能提示的 Ruby IDE 吗? at January 23, 2015

    https://github.com/dgutov/robe

    支持上下文语义级别的代码提示,这个只支持 Emacs。

    https://github.com/Valloric/YouCompleteMe#semantic-completion-for-other-languages 从 YCM 的文档上看,好像通过 Eclim 可以实现语义级别的 Ruby 代码提示,不过我不知道有没有人弄成功过。

  • 高考录取,纠结多日,终得尘埃落定,高中课本终于可以卖掉了! at July 14, 2014

    同学,你们高中数学教材是什么样的?能否照个照片或者告知下教材出版社?

  • 再回顾一遍 Ruby Gotchas at April 30, 2014

    http://ruby-china.org/topics/17742

    这精华加的太随便了吧,现在这种加精华的方式还不如以前按喜欢来排列,至少以前的方式就不会出现这种问题。

  • Array of Array Appending at April 29, 2014

    #1 楼 @santochancf よくやった、達也君 :thumbsup:

    x = [[]] * 4
    
    puts x.each {|a| puts a.object_id } 
    
    x = Array.new(4) { [] }
    
    puts x.each {|a| puts a.object_id }
    
    # >> 70261926896280
    # >> 70261926896280
    # >> 70261926896280
    # >> 70261926896280
    # >> 70261926887120
    # >> 70261926887100
    # >> 70261926887060
    # >> 70261926887040
    
  • 有什么能用的极简的论坛 / 小组? at April 24, 2014

    #17 楼 @ichord 你自己注册下就知道,我这么说很明显我就在用啊

  • 一个 Git 的问题 at April 24, 2014

    #8 楼 @1272729223 你 dev 是从哪个分支 checkout 出来的?master?如果切回 master 还有,你把里面该删的删了,commit,切回 dev 不就完了。

  • 一个 Git 的问题 at April 24, 2014

    .gitignore 只影响 Git 是否 Track 这些文件,而不是影响你的工作目录下面到底有什么。

    如果你创建 dev branch 时的 branch 没有这些文件夹,那么你在 dev commit 之后,切换回去就不应该有。

  • 有什么能用的极简的论坛 / 小组? at April 24, 2014

    Basecamp and Campfire 都有免费的版本,如果不超过 3 个人。

  • deploy rails4 with nginx and passenger need run "bundle exec rake assets:precompile"? at April 19, 2014

    @Rei

    #3 楼 What error -> What's the error

    #8 楼 How you link css assets in layout? -> How do you link css assets in layout?

    #9 楼 does you -> do you

    一个技术过关的工程师不应该在这些地方犯错误,没恶意,不过我觉得既然用了英文,写对这些就很重要。

  • [求助] Core::User 转换成 ‘core/user’ 和 :core_user 怎么写比较简单? at April 07, 2014
    require 'active_support/inflector'
    
    Core::User.name.underscore # => "core/user"
    
    Core::User.name.underscore.gsub('/', '_').to_sym # => :core_user
    
  • 求教大神数组内对象不重复 (已解决) at April 07, 2014

    #8 楼 @night_song

    * Removed deprecated `Array#uniq_by` and `Array#uniq_by!`, use native
      `Array#uniq` and `Array#uniq!` instead.
    

    4.1 就要删掉了,因为本身 Ruby 的Array#uniq方法就可以接收 block,不过我觉得uniq_by这个名字还是比uniq更适合在后面接 block。

  • 求教大神数组内对象不重复 (已解决) at April 05, 2014

    @Victor

    740     # Specifies whether the records should be unique or not. For example:
    741     #
    742     #   User.select(:name)
    743     #   # => Might return two records with the same name
    744     #
    745     #   User.select(:name).distinct
    746     #   # => Returns 1 record per distinct name
    747     #
    748     #   User.select(:name).distinct.distinct(false)
    749     #   # => You can also remove the uniqueness
    750     def distinct(value = true)
    751       spawn.distinct!(value)
    752     end
    753     alias uniq distinct
    754
    755     # Like #distinct, but modifies relation in place.
    756     def distinct!(value = true) # :nodoc:
    757       self.distinct_value = value
    758       self
    759     end
    760     alias uniq! distinct!
    

    alias 过了,一个意思,我倒觉得楼主没考虑那么多。

    PS:话说这文档是不是错了?distinct 了两次?

  • 求教大神数组内对象不重复 (已解决) at April 04, 2014
    Array#uniq
    Array#uniq!
    
  • a.blank? ? b : a 怎么写来的方便? at April 04, 2014
    require 'active_support/core_ext/object/blank'
    
    a.presence || b
    
  • Software Design 中文版 第一期 样书 at April 01, 2014

    #4 楼 @tuliang 后面好几期都已经翻译过了,只不过还没到出版的时间。还会有一本叫《WEB+DB PRESS》的杂志,也是日本的,最早一期估计要 5 月份才能发。

  • “Welcome aboard” 页面是如何生成的? at March 30, 2014

    https://github.com/rails/rails/blob/master/railties/lib/rails/welcome_controller.rb https://github.com/rails/rails/blob/master/railties/lib/rails/templates/rails/welcome/index.html.erb

  • 如何快速判断一个 hash 里是否有 nil 或者空值 at March 23, 2014

    #9 楼 @Rei :thumbsup:

  • 如何快速判断一个 hash 里是否有 nil 或者空值 at March 23, 2014

    #4 楼 @Rei #7 楼 @swordray

    难道不应该是

    a.all? { |key, _| params[:a][key].present? }
    

    一个参数把键/值都迭代了。

  • 如何快速判断一个 hash 里是否有 nil 或者空值 at March 23, 2014
    a = {
      b: "xxx",
      c: "lll",
      d: "ooo",
      f: "ui"
    }
    
    params = {}
    
    params[:a] = {
       b: "x",
       c: "c",
       d: "ds",
       f: "f",
       g: "g"
    }
    
    params[:b] = {
       b: "x"
    }
    
    params[:c] = {
       b: "x",
       c: "c",
       d: "ds",
       f: "",
       g: "g"
    }
    
    def not_empty(str)
      str.to_s.strip.length != 0
    end
    
    a.all? { |key, _| params[:a].has_key?(key) && not_empty(params[:a][key]) } # => true
    a.all? { |key, _| params[:b].has_key?(key) && not_empty(params[:b][key]) } # => false
    a.all? { |key, _| params[:c].has_key?(key) && not_empty(params[:c][key]) } # => false
    
    

    从@rei的方法改的,有 ActiveSupport 的话,用 present?就行。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 22, 2014

    #44 楼 @aptx4869 No,看反响,意义不大,故作罢。

  • 重复代码怎么才能更好的消除? at March 18, 2014
      def restore_record(record_id, activities)
        self.send("restore_#{self.name.downcase}", record_id, activities) if can_restore?
    end
    
      def can_restore?
        ["Prize", "Apply", "Activity"].include?(self.name)
      end
    
      def restore_prize(record_id, activities)
        activity_ids = activities.map(&:id)
        record = self.deleted.find(record_id)
        record.restore if activity_ids.include?(record.activity_id)
      end
    
      def restore_apply(record_id, activities)
        activity_ids = activities.map(&:id)
        record = self.deleted.friendly.find(record_id)
        self.restore(record.id, :recursive => true) if activity_ids.include?(record.activity_id)
    end
    
    def restore_activity(record_id, activities)
      record = self.deleted.friendly.find(record_id)
      self.restore(record.id, :recursive => true) if activities.include?(record)
    end
    

    不要return true或者return false。另外我也没觉得代码有多少重复的地方。我倒觉得这个方法本身返回布尔值很不合理。

    从restore_record的方法名看,这个方法不应该返回布尔值,只要不依赖返回值,一堆条件语句删了后,应该好些,具体的还要根据实际情况自己重构,没有上下文,基本上是谈不上重构。

    另外,推荐你调用方法的时候把括号加上,方法参数也是

  • 我们不组织个 “每周一题” 之类的活动吗? at March 11, 2014

    #39 楼 @quakewang 挺简洁的实现方法,我没想到有这么个思路。

    我觉这个 before_filter 不算很简单,也不算很难,但想实现的好也是绝对不是一件简单的事,其实比较符合我的初衷。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 10, 2014

    #34 楼 @swordray 顶楼我也写了,我觉得没有必要单独作成一个 App,我觉得在这里开展比较合适。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 10, 2014

    更新一下我预想的一道题:

    例如实现一个 Rails 中的 before_filter 或者 around_filter:

    class PeopleController < ApplicationController 
      before_filter :locate_person, :only => [:show, :edit, :update]
    
      def show
        puts "showing a person's data"
      end
    
      def edit
        puts "displaying a person edit form"
      end
    
      def update
        puts "committing updated person data to the database"
      end
    
      def create
        puts "creating a new person"
      end
    
      def locate_person
        puts "locating a person"
      end
    end
    

    或者是实现一个简单的 XML Builder 之类的,我所想的题目应该是尽可能和 Ruby 相关的,题目看一眼所有人都明白意思,不会对题目本身有什么疑惑,题目本身也没有不需要很严格的限制,例如输入、输出。

    题目的解决时间根据个人水平的不同,花费 15-60 分钟为最佳。因为我觉得像这样的余兴活动,只有在不花费过多时间的情况下,才可以长久。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 10, 2014

    #29 楼 @ctrlaltdeletel 我预想的题目不是这种 Puzzle 类的风格,就是类似:

    The Problem: Example Input: Example Output:

    这种类似 ACM 的题目,我觉得很多时候,使用 Ruby 都不如其它语言合适,而且很容易写成算法类的代码,就像我在顶楼提到的后面一种。

    #30 楼 @krazy

    Thin 作者这个属于撘个脚手架,你来进一步完成,这也不太适合在论坛展开啊,太广了。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 10, 2014

    #27 楼 @swordray 那里的题目我看了下,还是偏益智类的题目,算是 Quiz 吧。

    我比较倾向于实际可能会用到的代码,我觉得组织很多的人,重造同一个轮子,并且这个轮子是一个大家平常一直在用,但却不是很清楚怎么实现的功能。这样大家可以看出来针对这个大家都很熟悉的功能,怎样地实现是比较好的。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 09, 2014

    #21 楼 @swordray 除及其特殊的情况,使用单行代码能实现的功能应该是十分有限。并且为了使用单行实现,刻意降低可读性,我觉得不会让人从中学到什么。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 09, 2014

    #20 楼 @aptx4869 有标准库以外的外部依赖我觉得也不合适。并且你提到音频过滤器,我觉得问题最好不要涉及到额外的一个领域(视频、音频、自然语言处理),因为宗旨是让尽可能多的人参与,这样的问题需要在回答问题之前,了解一下相关领域的内容,否则便会无从下手。像这样的活动,如果做不到极低的参与门槛,我觉得应该算是很失败。

  • 我们不组织个 “每周一题” 之类的活动吗? at March 09, 2014

    #17 楼 @aptx4869 我觉得这种规模的问题不太适合在论坛这样的地方展开。

  • 1
  • 2
  • 3
  • …
  • 12
  • 13
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English