![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Ruby 1.9
horace_lee
这个作者很懒,什么都没留下…
展开
-
instantRails 和RedMine
Update (2011-11-29): 各位看官请注意,Win下的解决方案,instantRails已经不是首选,换Railsinstaller 感谢EngineYard 技术支持,winror一个强大支持 没有Devkit在win下安装gem会别扭死 当前支持如下: Ruby 1.9.2-p290 Rails 3.1.1 Bundler ...原创 2009-05-05 15:17:59 · 160 阅读 · 0 评论 -
动态定义类变量和类实例变量
[code="ruby"] class Mine attr_accessor :some_var def intialize @some_var = true end def my_number num self.class.__send__(:attr_accessor, "my_#{num}") self.__send__("my...原创 2012-03-01 04:52:58 · 147 阅读 · 0 评论 -
动态定义ruby子类,和判断是否定义
上篇有个标准的定义动态类变量 [code="ruby"] class MyClass class nil MyClass.new.my_method p MyClass.my_constant #=> "blah" [/code] 如果类也动态定义,那么子类和module怎么定义进去的 [code="ruby"] dynamic_name = "TestEval2"...原创 2012-03-01 04:59:44 · 199 阅读 · 0 评论 -
ruby 的回溯 正则表达式
[code="ruby"] password =~ /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}$/ #(?=.*\d) any thing with a number #at least one number one up case one down case [/code] [code="ruby"] ^ - Matches beg...原创 2012-03-03 02:48:06 · 236 阅读 · 0 评论 -
yield可以在block中吗?
类似如下的实现 [code="ruby"] a = lambda { puts 'in a' yield if block_given? } a.call { puts "in a's block" } [/code] 上面的调不到,使用如下: [code="ruby"] #ruby 1.8 a = lambda { |my_proc| puts 'in...原创 2012-03-06 10:58:52 · 103 阅读 · 0 评论 -
关于block和闭包的练习
关于block和闭包的练习 [code="ruby"] def example(num) puts puts "------ Example #{num} ------" end example 1 def thrice yield yield yield end x = 5 puts "value of x before: #{x}" ...原创 2012-03-06 11:25:21 · 66 阅读 · 0 评论 -
Ruby 1.9.3 p125 安装ruby-debug
[color=red]Update:[/color] 4/10/2012 直接换成 gem 'debugger' 老的ruby-debug更新有点慢啊 跑起来一模一样 运行下面的shell安装新版gem [code="sh"] # Install with: # bash < 'ruby-debug' end [/code] bundle update...原创 2012-04-05 00:50:20 · 98 阅读 · 0 评论 -
升级rails 3.2.3时候快速解决的小问题
[quote]uninitialized constant Test::Unit::TestCase::Assertions (NameError)[/quote] 解决办法是处理一下spec_helper [code="ruby"] ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environme...原创 2012-04-06 05:06:47 · 73 阅读 · 0 评论 -
Cucumber Capybara Selenium 如何触发一个dom的点击事件
就是 click_on 和 Press 只能针对button和link如果,有个页面元素是,javascript绑定的怎么触发 [code="js"] page.execute_script("$('#{css_selector}').trigger('click')") page.find('#element').trigger(:mouseover) page.execute_...原创 2012-04-06 12:50:29 · 197 阅读 · 0 评论 -
如何在Cucumber下运行ruby-debug
[code="ruby"] # Gemfile group :development, :test do # ... other gems here gem 'ruby-debug19', :require => 'ruby-debug' end # features/support/env.rb require 'ruby-debug' # features/st...原创 2012-04-07 00:19:57 · 108 阅读 · 0 评论 -
2种使用class_eval动态定义方法的格式
[code="ruby"] class MyClass def initialize(dynamic_methods) @arr = Array.new(dynamic_methods) @arr.each{|m| self.class.class_eval do define_method(m) do |*value| ...原创 2012-12-12 08:06:36 · 130 阅读 · 0 评论 -
Eloquent Ruby 读书笔记 续
运算符重载和Ruby风格的运算符重载 程序大概意思是,重新定义,文件类的比较方法。只要目录和文件名一样,就说这两个文件类一样。ruby的 [code="ruby"] class DocumentPointer attr_reader :folder, :name def initialize( folder, name ) @folder = folder @...原创 2012-02-27 23:15:14 · 75 阅读 · 0 评论 -
ruby 的 Enumerable 方法
grep 是===来判断是否存在符合条件的sub enumerable [code="ruby"] c = IO.constants c.grep(/SEEK/) #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END] res = c.grep(/SEEK/) {|v| IO.const_get(v) } res ...原创 2012-02-23 03:28:21 · 98 阅读 · 0 评论 -
也说说ruby inject
其实,没有什么太多说的,IE有的先链接过来 [url]http://biyeah.iteye.com/blog/1286449[/url] [url]http://www.iteye.com/topic/56291[/url] 下面的总结的挺好, 完了来回顾一下inject方法两种用法: [code="ruby"]enum.inject(init_value) {|mem...原创 2011-12-12 08:09:43 · 105 阅读 · 0 评论 -
ruby array中找出重复元素
[code="ruby"] #上文的inject现在用上了 module Enumerable def dups inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys end end [/code] [code="ruby"] arr = %w{foo bar baz bar baz qu...原创 2011-12-14 12:28:45 · 1025 阅读 · 1 评论 -
ruby 1.9 rails 3.1 ruby debug的问题
[color=red]update(2015/05/12):[/color] for rbenv [code="ruby"]gem install debugger -- --with-ruby-include=/home/hlee/.rbenv/versions/1.9.2-p330/lib/ruby/gems/1.9.1[/code] [color=red]update ...原创 2011-12-20 23:06:18 · 116 阅读 · 0 评论 -
脱离rails环境单独使用capybara以及使用capybara测试拖放
[code="ruby"] require 'rubygems' require 'capybara' require 'capybara/dsl' Capybara.run_server = false Capybara.current_driver = :selenium Capybara.app_host = 'http://www.google.com' module...原创 2012-01-17 12:49:03 · 86 阅读 · 0 评论 -
ruby 1.9 简单的文件操作
[code="ruby"] #读文件 f = File.open("myfile.txt", "r") f.each_line do|line| puts "I read this line: #{line}" end [/code] [code="ruby"] File.foreach("myfile.txt") do|line| puts "I re原创 2011-11-21 00:23:36 · 82 阅读 · 0 评论 -
ruby 1.9 irb rails console不能用readline问题
[color=darkred]Update: 2012/03/27[/color] 当前版本ruby1.9.3p135 ubuntu 11.10 解决办法先试试 [code="ruby"]rvm requirements #先安装依赖的包 rvm remove 1.9.2 rvm install 1.9.2 [/code] 遇到问题是rvm use用不了,其他都能用,提示 ...原创 2011-11-24 02:49:17 · 101 阅读 · 0 评论 -
关于json
js.erb [code="ruby"] alert('New object id: ' + );[/code] 在这个文件里读rails变量到js,实际是可以直接运行rails 标注一个render json需要include和only选择的 [code="ruby"] respond_to do |format| format.html # ind...原创 2011-11-26 22:03:29 · 74 阅读 · 0 评论 -
Ruby On Rails 面试系列七,一个面试练习题
现在面试流行让你写代码放到github上,这是其中一个要求: Please create a todo-list application with the following capabilities: Login and account creation RSpec & Cucumber Tests Bonus points for incorporating Aja...原创 2011-11-28 12:26:39 · 678 阅读 · 0 评论 -
带序号循环Hash
[code="ruby"] hash.keys.each_with_index do |key, index| value = hash[key] print "key: #{key}, value: #{value}, index: #{index}\n" # use key, value and index as desired end [/code] [c...原创 2011-12-02 23:17:36 · 70 阅读 · 0 评论 -
ruby 1.9.3-p286 debugger-linecache
[color=red]update(05/13/2013)[/color] [color=red]rbenv:[/color] 解决方案: [code="ruby"]gem install debugger-linecache -- --with-ruby-include=/home/user/.rbenv/versions/1.9.3-p392 [/code] [code="...原创 2012-10-18 21:10:20 · 124 阅读 · 0 评论 -
brew unable to unlink old 'README.md' (Permission denied)
rvm install 2.0.0 met problem about [url=https://github.com/mxcl/homebrew/issues/2906]brew[/url] [quote]brew unable to unlink old 'README.md' (Permission denied)[/quote] solve problem by: [...原创 2013-02-27 23:50:15 · 196 阅读 · 0 评论