Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Hooopo
@hooopo
管理员
第 8 位会员 / 2011-10-28

[email protected]
nil
北京
160 篇帖子 / 3013 条回帖
360 关注者
0 正在关注
74 收藏
聪明的妖怪录下了唐僧的紧箍咒
打赏作者
GitHub Public Repos
  • oh-my-github-circles 47

    GitHub User Circle Generator Using GitHub Actions

  • hackernews-insight 21

    Hackernews Insight using TiDB Cloud

  • repo-track-pipeline 6

    🔄 A flexible open-source data pipeline for seamlessly syncing data from any repository to your da...

  • oh-my-github-pipeline 6

    🔄 A flexible open-source data pipeline for seamlessly syncing data from any github user to your d...

  • chatgpt-xiaoai 3

    小爱音箱集成LLM,SaaS 服务

  • repo-contributor-circles 1

    GitHub repo contributor circles generator.

  • ossinsight-x 1

    Automatically post trending repos to Twitter every day.

  • mi-service 1

    XiaoMi Cloud Service for mi.com

  • hooopo 0

  • streamlit-echarts-demo 0

    Demo for Streamlit ECharts component

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [上海] 想和码婆一起工作吗? at 2012年06月29日

    看错了

  • [北京] 招聘 Rails 攻城狮 / 前端美工 at 2012年06月29日

    #8 楼 @ywencn #9 楼 @abitno 照片很赞

  • 发现一个很有趣的 commit at 2012年06月29日

    这个也挺有意思的:http://rubyonrails.org/core

    By day, Aaron Patterson (tenderlove) is a mild mannered programmer for AT&T Interactive whose Ruby code is almost as good looking as him. By night, he dons his Pink Warrior suit which gives him the power to contribute to many Open Source projects such as nokogiri, Ruby, and Rails. If you have seen someone kissing Matz or DHH at a conference, it was probably him. You can find him on twitter, or read his blog.


    Jon Leighton is a freelance Ruby consultant from Oxford, UK and (probably) the only core member who defiantly refuses to use a Mac! When he occasionally goes AFK, Jon enjoys dangling from small bits of rock on the sides of cliffs and mountains. You can follow @jonleighton, or read his blog.

  • 多态关联用的多吗? at 2012年06月29日

    #9 楼 @zhenning 单表继承也用..

  • 有人用过 submodule 这个特性吗?怎样 ignore 比较合理? at 2012年06月28日

    #8 楼 @yuan 我觉得 submodule 的作用就是一个目录组织功能,如果项目依赖于这种组织结构的话就说明设计的问题。

  • 有人用过 submodule 这个特性吗?怎样 ignore 比较合理? at 2012年06月28日

    #9 楼 @fsword 几乎所有语言都有依赖管理和依赖隔离工具吧

  • 大家的 RSS 列表里有什么好的推荐的么 at 2012年06月27日

    https://gist.github.com/2814326

  • 有人用过 submodule 这个特性吗?怎样 ignore 比较合理? at 2012年06月27日

    可以说说用 submodule 的好处么? 感觉如果是 rails 项目,这东西根本用不到啊。

  • to_s,to_str 和 inspect at 2012年06月27日

    #9 楼 @jjym 这篇讲的也不错:http://blog.bigbinary.com/2012/06/26/to_str-in-ruby.html

    If an object implements to_str method then it is telling the world that my class might not be String but for all practical purposes treat me like a string. If a class defines to_str then that class is telling the world that altought my class is not String you can treat me like a String.

  • 关于飞信的鲜为人知的秘密 at 2012年06月27日

    #3 楼 @lifuzho 哈哈哈 那东西对方不在线好像会丢信息

  • 1 at 2012年06月26日

    #9 楼 @Guest 是 Rails 的兼容性吧。。

  • rvm gemset copy 失败 at 2012年06月25日

    #13 楼 @yuan 在 rails2 的项目用 bundler,然后 gemset 就可以扔了。

  • 问个问题,怎么解决手机端程序生成主键冲突问题 at 2012年06月25日

    #11 楼 @lanisle 我就是这个意思啊 客户端保存关系和同步状态 和什么 id 没一点关系

  • 问个问题,怎么解决手机端程序生成主键冲突问题 at 2012年06月25日

    #3 楼 @piginzoo 可以离线创建? 手机端的关联和服务器端的关联不需要有任何关系呀。

  • and 和 && 是不同的 at 2012年06月25日

    o(∩∩)o...哈哈 p (alien and speaks_english ? 'hello' : 'silence') 就一样了

  • 问个问题,怎么解决手机端程序生成主键冲突问题 at 2012年06月25日

    搞不清楚你的系统怎么设计的。。

  • 关于 attr_accessible :as => :admin 的一个疑问 at 2012年06月25日
    class Topic
      FIELDS = [:title, :content]
      attr_accessible *FIELDS
      attr_accessible *([:sticky] + FIELDS), :as => :admin
    end
    
  • 1.8.7 害死人 at 2012年06月25日

    一直就这样啊

  • Ruby-China 的安全机制需要改进 at 2012年06月24日

    #12 楼 @xds2000 你说的第一点类似 Heroku 这样的云平台了,Heroku 目前的做法是所有配置都存储在环境变量里,有专门工具去修改环境变量,并且每次环境变量修改之后代码重新 release 一个版本,可以 rollback

    我觉得(超级)管理员这个功能应该和配置没有关系,应该是数据库 seed 或One-off admin processes来做的事情。

  • Ruby-China 的安全机制需要改进 at 2012年06月24日

    我觉得是 ruby china 的管理员功能实现的很怪异。

    普通做法是在 user 表上加一个标记。

    现在 ruby china 的做法是在配置里存一个邮箱数组,通过判断用户的邮箱是否在数组里来判断是否有管理权限。

    带来的问题就是: 1.添加管理员之后要重启 2.管理员改邮箱后就丢失了管理权限 3.只有有权限修改服务器上配置的人才能分配权限(这个也可以当作优点)

  • to_s,to_str 和 inspect at 2012年06月24日

    #9 楼 @jjym 嗯 就是动态语言里的多态、ducking type、面向行为什么的....

  • to_s,to_str 和 inspect at 2012年06月24日

    #6 楼 @jjym 定义了 to_str 就像一个对象贴上这样的标签:“我是一个字符串噢!字符串们我们可以一起 OOXX 啊”

    而定义了 to_s 就表示“实在没有办法了你也可以把我变成字符串。至于会变成什么样子鬼知道呢!”

    ruby-1.9.3-p0 :052 > class XX
    ruby-1.9.3-p0 :053?>   def to_str
    ruby-1.9.3-p0 :054?>     "ooxx"
    ruby-1.9.3-p0 :055?>     end
    ruby-1.9.3-p0 :056?>   end
     => nil 
    ruby-1.9.3-p0 :058 > class CC
    ruby-1.9.3-p0 :059?>   def to_s
    ruby-1.9.3-p0 :060?>     "to_s"
    ruby-1.9.3-p0 :061?>     end
    ruby-1.9.3-p0 :062?>   end
    
    ruby-1.9.3-p0 :064 > "let's go " << XX.new
     => "let's go ooxx" 
    
    ruby-1.9.3-p0 :066 > "let's go " << CC.new
    TypeError: can't convert CC into String
    

    上面的代码演示了,如果你不定义 to_str,其他 str 根本没办法信任你。

    还有一方面就是,to_s to_str inspect 这三个方法的职责不同。 to_str 刚才说了是标识 acts like string inspect 是为了 debug 需要,检查对象内部状态(包括实例变量类变量等) to_s 是一种不负责任的强制转换,每个对象都有的。但一般不需要自己去修改。

  • to_s,to_str 和 inspect at 2012年06月24日

    #4 楼 @jjym 其实这里面有细微差别的。并且这样的差别并不影响初级使用者,但是高阶一点的使用者却可以用的很顺手。

    to_s means "You can turn me into a string", while to_str means "For all intents and purposes, I am a string".

    to_s 是表示把一个对象的字符串状态呈现出来,不管结果如何。只要得到字符串的状态。 所以普通对象一般 to _s 后都是这样"# < A:0x9c5ce8 >",几乎没有意义。

    而一般对象是没有定义 to_str 的,如果定义了就表示这个对象能完美的呈现字符串状态(比如 Path 对象,Rails.env),在与字符串做相关操作(join / gsub/ <<等),就会优先调用 to_str。

    ruby-1.9.3-p0 :050 > Rails.env.class
     => ActiveSupport::StringInquirer 
    ruby-1.9.3-p0 :051 > "hello " << Rails.env
     => "hello development"
    

    简单的说,一个对象定义了 to_str 就表示它 acts_like_string,但这种实现比继承和 mix-in 要轻量很多。

  • to_s,to_str 和 inspect at 2012年06月23日

    #2 楼 @zw963 写给不了解的:-)

  • 动态语言是否应该有一套 api 规范? at 2012年06月23日

    一种语言的不同版本都保证不了。。

  • | 结 | "_"在 ruby 中代表什么 at 2012年06月23日

    #4 楼 @sectic pry 和 irb 里都是打印 3 次啊 没有报错

  • | 结 | "_"在 ruby 中代表什么 at 2012年06月23日

    这不是 Ruby 里的,是 IRB/Pry 特有的变量,存储REPL的 eval 过程的结果。

  • ruby 的正则里有个前视断言,那有木有后视断言涅? at 2012年06月23日

    你说的后视断言是这样吧;

    [19] pry(main)> "123 456 789.012"[/(?<=\.)(\d+)/]
    => "012"
    
  • ruby 的正则里有个前视断言,那有木有后视断言涅? at 2012年06月23日

    用括号捕获就行了

    [17] pry(main)> "123 456 789.012"[/(\d+)\.(\d+)/, 1]
    => "789"
    [18] pry(main)> "123 456 789.012"[/(\d+)\.(\d+)/, 2]
    => "012"
    
  • 上一页
  • 1
  • 2
  • …
  • 86
  • 87
  • 88
  • 89
  • 90
  • …
  • 108
  • 109
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English