Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
Leslie Zhang
@fighterleslie
Member
NO. 23338 / 2015-11-04

[email protected]
Udesk
北京
1 Topics / 90 Replies
1 Followers
18 Following
133 Favorites
Keep calm and move on!
GitHub Public Repos
  • incident_management_sh... 1

    share on incident management

  • fighterleslie 0

    my secret! repo

  • decoding-bitcoin 0

    A platform with tons of interactive demos and exercise to learn bitcoin

  • awesome-oss-alternatives 0

    Awesome list of open-source startup alternatives to well-known SaaS products 🚀

  • go-gin-example 0

    An example of gin

  • awesome-productivity 0

    A curated list of delightful productivity resources.

  • test-smells 0

    A workbook repository of example test smells and what to do about them.

  • qwerty-learner 0

    为键盘工作者设计的单词记忆与英语肌肉记忆锻炼软件 / Words learning and English muscle memory training software designed fo...

  • awesome-nocode-lowcode 0

    A curated list of awesome nocode and lowcode ressources for building software without code.

  • awesome-database-learning 0

    A list of learning materials to understand databases internals

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 关于事件捕获与事件冒泡的疑问 at February 25, 2016

    事件传播三阶段:

    • capture phase(事件捕获)
    • target phase(处于目标)
    • bubbling phase(事件冒泡)

    在 target phase,event handler 被调用的顺序不再遵循先捕获,后冒泡的原则,而是严格按照 event handler 注册的顺序

    在例子中,

    btn.onclick = function(){
        console.debug("冒泡1.Click btn");
    }
    

    先于

    btn.addEventListener("click",function(){
        console.debug("捕获1.Click btn");
    },true);
    

    注册,故而先执行。

    要改变二者的执行顺序,只需要改变两段源码的顺序即可。

    W3C 规范:

    Next, the implementation must determine the current target's candidate event listeners. This must be the list of all event listeners that have been registered on the current target in their order of registration. [HTML5] defines the ordering of listeners registered through event handler attributes. Once determined, the candidate event listeners must not be changed. Adding or removing listeners does not affect the current target's candidate event listeners.

    StackOverflow 更多讨论:

    • http://stackoverflow.com/questions/11841330/event-order-capturing-bubbling
    • http://stackoverflow.com/questions/18103391/usecapture-in-addeventlistener-behaves-strangely?lq=1
  • 新手求教,关于 main 对象的一些疑问 at February 23, 2016

    main 的祖先链里并没有 Module,这几个方法是怎么进去的?

    这几个方法是 main 对象的 private singleton method,定义在 main 对象的 metaclass 里,因此可以被 main 对象调用

    # at top-level
    self.private_methods - Object.private_instance_methods  # => [:define_method, :include, :private, :public, :using]
    
    self.singleton_class.private_instance_methods(false) #=> [:define_method, :include, :private, :public, :using]
    

    为什么要在 main 里加上这些方法?

    个人感觉可以用四个字形容:将错就错。Ruby 也不是一门完美的语言,top-level 的设计一直也来也很有争议。顶层的 main 对象时而表现得像一个 Object 类的普通实例,时而表现得像一个 Module。严谨地讲,这是 Ruby 的一个 bug,然而 Matz 并不准备改,所以只能将错就错下去了。

    更多讨论:

    • What is the Ruby Top-Level?
    • Feature #6609: Toplevel as self extended module
    • Kill the Proxy and Save Toplevel

    Rubinius 源码: https://github.com/rubinius/rubinius/blob/master/core/main.rb

  • 《Effective Ruby:改善 Ruby 程序的 48 条建议》Effective Software Development Series” 系列经典著作 at February 23, 2016

    Effective 系列确实都是好书!

  • [结束] 送几本《Docker 即学即用》 at February 20, 2016

    [email protected]

  • 怎么搞清楚 FormHelpers 里面的方法对应产生的 HTML attributes 在 Rails 里的作用和相互关系? at February 19, 2016

    #2 楼 @stardiviner HTML 属于 Web 前端的知识,找本前端的书看看就明白了,其实挺简单的。

  • 想问一下,Ruby 当中是如何解决 Import 这个问题的? at February 18, 2016

    Rails 里面能直接使用 helper 方法是因为约定大于配置,Rails 源码中已经自动加载文件并 include 了相关模块。

    Ruby 里用 Kernel#require 和 Kernel#require_relative 显式加载执行其它文件中的代码,也可以使用 Kernel#load 和 Module#autoload。

    其实这反映了 Python 和 Ruby 的两种不同理念,Python 强调 explicit is better than implicit , submodule.my_method 能清晰地反映出 my_method 是在哪个文件中定义的;而 Ruby 更强调简洁,更含蓄一些,直接使用 my_method 的缺点是你不能一眼看出该方法定义在哪里,需要用 method(:my_method).source_location 查看。各有利弊!

  • [杭州] 小杉果研发中心诚邀一名中高级 Rails 伙伴加入我们!~~~ at February 14, 2016

    #4 楼 @zhang_soledad Amber 不是改名了吗?http://yehudakatz.com/2011/12/12/amber-js-formerly-sproutcore-2-0-is-now-ember-js/

  • 为什么 Ruby 的视频教程这么少? at February 09, 2016

    不觉得少啊,我给你列举几个:

    • Ruby Tapas
    • GoRails
    • Rails Casts
    • Rails Casts China
    • Rails Tutorial(有 Screencasts)
    • One Month Rails
    • Confreaks
    • Tutsplus, PluralSight, Lynda 等知名在线教育网站
    • 万能的 Youtube
  • 为什么在线转换 slim2html 无法使用 http://slim2html.raving.systems/ at January 27, 2016

    安装 slim 这个 gem 后,会同时安装一个命令 slimrb,可以在命令行下将 slim 文件转换为 html/erb 格式。

  • Lotus 框架重命名为 Hanami 了 at January 25, 2016

    #3 楼 @nong 一个意思,hanami 就是“赏花的艺术”,用日语是为了向 Matz 致敬

  • Lotus 框架重命名为 Hanami 了 at January 25, 2016

    #1 楼 @darkbaby123 我感觉普通的开源项目重名没什么大问题,但是这个牵扯到了知识产权,毕竟 IBM 先注册了商标,应该说存在一定的法律风险(参考 javaeye 被迫改名 iteye 一事,域名都不能随便用)。

  • 打算卖掉 ruby.gg 这个域名。。。 at January 17, 2016

    学费米

  • Sinatra 多个路由如何合并? at January 17, 2016

    #8 楼 @jay_li 这个好!

  • 学驾照有用吗? at January 16, 2016

    过来人表示:趁还在学校,赶紧考啊!

    最主要的,就是预期近几年根本没有开车的机会,让我为这个东西支付成本,实在是理解不了

    可以这样理解:工作后的时间成本比学生期间的昂贵太多,为了将来省钱省时间,早点学!

  • Ruby China on PostgreSQL at January 16, 2016

    很赞,已 star! 👍

  • 一些短小的例子:101 Ruby Code Factoids at January 14, 2016

    👍

  • 求大神指点 ruby 安装在 windows 上的相关问题 at January 14, 2016

    参考 https://ruby.taobao.org/,不管是啥操作系统,在天朝,最主要的是设置 gem 的源。

    gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/

    安装 Bundler 并在命令行运行 bundle config mirror.https://rubygems.org https://ruby.taobao.org

  • Ruby 如何复制一个方法 而不是复制一个方法的值 at January 10, 2016

    Ruby 中有 alias 关键字和 Module#alias_method 方法,用于为方法设置别名。

  • 自从卸载了 rmagick 以后就 install 不回去了...不得已来求助~ at January 08, 2016

    checking for outdated ImageMagick version (<= 6.4.9)... no

    你的 ImageMagick 版本是啥?

    Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

    检查 mkmf.log

    Let me google that for you

    You are not alone.

    http://stackoverflow.com/questions/13963404/rails-and-os-x-how-to-install-rmagick

  • [已解决] 有人能安装 rails v5.0.0.beta1 吗? at January 08, 2016

    gem i rails -v 5.0.0.beta1

    Inside Gemfile: gem 'rails', '5.0.0.beta1'

  • 全新的站内搜索上线 at January 06, 2016

    👍

  • 闯过这 54 关,点亮你的 Git 技能树 at January 04, 2016

    #19 楼 @oreo 这是个 bug,在 Linux 平台的 git 2.5 或 2.6 版本上出现。不过好消息是这个 bug 昨天应经被修复了,gem update githug 然后重新运行 githug 即可。

  • Happy 2016! AMA - Ask Me Anything :) at January 01, 2016
    1. How is the job market for software engineers in Australia?
    2. How is the job market for Ruby on Rails developers in Australia?
  • Debian 创始人 Ian Murdock 自杀身亡 at December 31, 2015

    #2 楼 @lgn21st Debian 这个名字是 Debra (Ian 的妻子) 和 Ian 的组合

  • 除了 Dash 还有什么好的在线 API 文档推荐吗?谢谢 at December 31, 2015

    Zeal Velocity LovelyDocs

  • Ruby 微信开发群 at December 27, 2015

    支持开节点!

  • Ember.JS 编写的 Ruby China 客户端 at December 25, 2015

    @wppurking

    Great work.

    The link is dead, new demo address should be http://ember-rc.daoapp.io/

  • kernel 中的 puts 方法是模块实例方法还是模块方法 at December 23, 2015

    #13 楼 @runup

    简单的说,虽然 puts 和 cc 都是 private method,但是 puts 是定义在 Kernel 模块中,cc 方法是定义在 KernelModule 模块中。Kernel 是一个特殊的模块,它和你自己定义的 KernelModule 模块有一些行为上的不同。

    详细地说,这涉及两方面的知识:

    1. Ruby 的对象体系
    2. 方法的查询机制
    module KernelModule
      def cc
        puts "this is the private method"
      end
      private : cc 
    end
    
    class FatherClass
      include KernelMdoule
    end
    
    class SonClass < FatherClass
      cc
    end
    
    SonClass.ancestors  # => [SonClass, FatherClass, KernelModule, Object, Kernel, BasicObject]
    SonClass.class.ancestors # => [Class, Module, Object, Kernel, BasicObject]
    

    Kernel 模块已经在 Object 模块中 include,而几乎所有的 Ruby 类都是直接或间接地继承自 Object,所以 Kernel 模块会出现在所有类的 ancestors 列表中。当在 receiver 上调用 cc 方法时,Ruby 解释器会沿 receiver.class.ancestors 逐级查找是否有 cc 的定义,如果找到,会调用 cc 方法,同时不再向上查找;如果遍历 ancestors 而没有找到,则会在 receiver 上调用 method_missing 方法,一般情况下会抛出 NoMethodError 错误。

  • kernel 中的 puts 方法是模块实例方法还是模块方法 at December 23, 2015

    #8 楼 @runup

    但是在类中进行调用 puts 方法(puts "method two"),与实例方法(puts 是 private instance method)只能被实例化对象调用相违背。

    Good question. 你的疑惑是为什么在 KernelMethod 这个类上可以调用 puts,因为 KernelMethod 这个类是 Class 类的实例对象(Ruby 中,一切值都是对象。)

    KernelMethod.class  # => Class
    KernelMethod.instance_of?(Class)  # => true
    
    
  • kernel 中的 puts 方法是模块实例方法还是模块方法 at December 22, 2015

    @runup

    我试着解答一下:

    问题 1:

    obj.puts("this is the Kernel method") #报错 private method puts

    puts 是 private instance method。private 的意思就是不能显示地指定 receiver object。你在这里显式指定 obj 为 receiver,当然会报错啦。

    问题 2: 你这里笔误了吧。class SonClass < KernelClass 应该是 class SonClass < FatherClass 才对。 而且,你调用 cc 方法的时候,receiver 是 SonClass,而不是 SonClass 的实例,当然获取不到实例方法了。

    问题 3: Ruby 文档的确有问题

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