• r c

  • 泪流满面啊,发了多少个扑街帖啊`~~

  • 这让人有点蛋疼,定义一个类方法,五种途径:

    #1
    class Person
      def self.species
        "Homo Sapien"
      end
    end
    #2
    class Person
      def Person.species
        "Homo Sapien"
      end
    end
    #3
    class Person
      class << self
        def species
          "Homo Sapien"
        end
      end
    end
    #4 
    class << Person
      def species
        "Homo Sapien"
      end
    end
    #5
    Person.instance_eval do
      def species
        "Homo Sapien"
      end
    end
    

    以上引自代码示例引自http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/,略有改动。 定义一个类方法而已,为什么要有这么多种方法存在? 如果再加上一种变态的 class_eval 的示例:

    #6
    class Foo
    end
    metaclass = (class << Foo; self; end)
    metaclass.class_eval do
        def species
          "Homo Sapien"
        end
      end
    end
    

    .....那就是 6 种方法了. 而后,这数种方法,在定义方法的范围,self 指代不同的对象,有的指向 Foo 类,有的则指向 Foo 类的 metaclass.有的打开了一个新的 scope(可以调用外面的变量),而有的则不可以. 用 yehada katg 的话来说:'At this point in other articles on this topic, you’re probably struggling to keep all of the details in your head; it seems as though there are so many rules.' 这么多规则让人怎么记它 ! 让人怎么不弄乱它! 一项操作,弄 6 种(可能更多)solution 出来,有必要吗?值得吗? 事实上,有必要的。因为这数种方法虽然在效果上看起来没有区别 (不就是定义了个类方法吗!).但实际上这中间的细微差异 (self 的不同,scope 的不同) 是为不同的要求而特意设计的。比如说,元编程. 这里举个例子:

    name = "foo"
    var = "bar"
    metaclass = (class << String; self; end)
    metaclass.class_eval do
      define_method(name) do
        puts var
      end
    end
    String.foo # bar
    

    这里,因为 class_eval 开了一个新的 scope,所以,可以直接调用之前调用之外的变量 name 与 var.而这样做却是不行的:

    name = "foo"
    var = "bar"
    class Foo
      define_method(name) do
        puts var
      end
    end
    Foo.foo # bar
    

    这样也不行:

    name = "foo"
    var = "bar"
    class Foo
      class << self
        define_method(name) do
          puts var
        end
      end
    end
    Foo.foo # bar
    

    因为class Foo, class<<Foo, class Foo;def self.bar;end;end, 以及class Foo;def Foo.bar;end;end这几种方式都打开了新的 scope(作用域).直接的结果是,对外部环境的 scope 调用不着。

    哪一天你需要这样用元编程,但是不知道如果控制作用域,what are you going to do?定义一个动态存取的实例变量?或者干脆用类变量?

    事实上,对这些细节的使用,远远不只元编程这么个例子这么简单。在开发的过程中,你永远不知道下一刻你会遇到多诡异的要求。当然,大部分情况下你可以想出办法来解决这些问题。但是,很多时候,最直接有效的解决办法可能就直接隐藏在这些小细节里。引用乔帮主的一句话:you can't connect the dots looking forward;you can only connect them looking backwards

    扯了这么多,只是要分享一点心得:多种途径实现一种方法,并不是给你的大脑加负的。而是为了实现强大的功能而特意设计的.多途径得出的结果,看似效果相同,实际上,却隐藏了许多细微的差别。而这种设计的目的,就是为了让我们能根据不同的需要,利用这些差异更便利地得到自己想要的。

    最后,再次推荐一下:http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the-self/ 这里面的探讨很深入,有助于大家进一步理解。

  • 这里引一个老外的解决方案: ... to hope for ie6 support, but I think that it will be difficult to make bootstrap compatible. I'm using a js library called moderizr.js to add classes to the html tag that tells what the browsers capabilities are and then making special css classes that will allow ie6 to gracefully downgrade as much as possible. I think that it is an alright solution. It won't look exactly the same, but it still should work.

  • #5 楼 @Macrow 你推荐的几个 css framework 似乎都是从 ie7 开始支持的。IE6 完全木有办法啊~~~。 说起来关于 bootstrap 是否需要 ie6 的问题。在 github 上有一贴 issue 讨论过。我也去凑过热闹。不过人家的态度很明显,打死不支持 IE6,不是不能,是不想。 https://github.com/twitter/bootstrap/issues/737#issuecomment-3136233

  • @_@ 我表示我一直被语言玩~~~ 一直努力争取翻身做主人。

  • 伟大的 GFW 啊,你是现代的万里长城,你是二十一世界 N 大奇迹之一。

  • 我这边只能通过一个叫 Easy Radius 的软件来连接上网。这个软件只在 windows 下运行。于是装好了的 ubuntu 没法联网。我试图用 Wine 来运行它,但是...失败...所以一直只能在 windows 里蛋疼~~~现在想来,虚拟机似乎也是个不错的选择。

  • #6 楼 @daqing ,木有在 github.com 上开源?

  • ** 好吧,要如何报名?第一期结束了,可以往后排期吧**

  • #4 楼 @jhjguxin 谢谢了~~ 问题应该就是出在这里了,确实没有做过组相关的设置

  • #709 飘过~~~

  • #2 楼 @jhjguxin 我用的 nginx 作为 web 服务器。 我要问的问题是: 以前部署项目时都没有出现过这样的问题?同样的流程部署这次却出现权限问题? 为什么在 development 模式下没有出现问题而在 production 之下却出现了? 按理而言应该是 nginx 调用 passenger 模块再由 passenger 来调用 rvm-ruby-1.9.3,再调用 gem 中的 paperclip,再由 paperclip 来处理上传图片,并将之写入至本地文件系统之中,为什么 paperclip 会没有写入权限? nginx.conf 的第一行#user nobody;我没有设置处于注释状态,因为这个的问题吗? 为啥我的 rvm 木有写入权限?难道不是用 root 权限安装的?

  • @_@#木有人理~~

  • 我也是,现下正在家待业,同样不熟悉 redmine.

  • Add to PATH

  • [上海] Ruby 相关职位 at 2012年02月07日

    @_@ ! 我表示在深圳的压力相当大啊~~~ 在招聘网上搜索“深圳,ruby,rails"几乎啥子都搜不到啊。 现在是无业游民了,这叫我肿么办才好啊~~~

  • 同求邀请

  • #3 楼 @fredwu ,相当 nice 的 ruby learning 站点呢~~~

  • What a shame! Can not go to work in Beijing.

  • Can you understand this? at 2012年01月11日

    #1 楼 @ywencn,我..我..只是想测一下图片贴入.......,所以才放在杂谈区....

  • 谢谢了,现在运行良好~~ 看 ruby-china.org,我得把我没接触过的第三方支持好好了解解一下... #_# 漫漫菜鸟路~~~

  • 好吧,问题诡异地得到了解决。我所做的事情,就是重新运行起 mongodb,与 redis,并保持其持续运行。在运行rake assets:precompile./script/resque start时虽然依旧出现了set your logging level no lower than :info in production,但是,却是不影响其运行。

  • 我将出现这个 mongodb warning 的问题提交到 github.com 了,希望能有找到解决办法。 https://github.com/huacnlee/ruby-china/issues/175

  • 遇到和你一样的问题,这个 assets 的问题影响不大。我跳过这一步后遇到了另一个问题,即是在运行./script/resque start 时报错了:

    MONGODB [WARNING] Please note that logging negatively impacts client-side performance. You should set your logging level no lower than :info in production. /home/administrator/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/connection.rb:413:in `connect': Failed to connect to a master node at 127.0.0.1:27017 (Mongo::ConnectionFailure) 我去 stackoverflow.com 里去查过。在 mongdb 官网去查过,到 mongoid 去查过,直接在 google 里也查过,硬是没找到解决办法.... 有没有谁知道这个应该怎么弄?