随笔分类 -  ruby

上一页 1 2 3 下一页
ruby中的retry和redo
摘要:# retry用于处理异常中的begin/end代码块中,如果发生异常会重新运行 begin 和 rescue 之间的代码#当retry 被调用的话,begin 和 rescue 之间所有的代码都会被重新跑一次,并不会只跑片段代码或只跑发生异常的代码(0..5).each do |i| begin 阅读全文
posted @ 2017-01-20 12:53 c3tc3tc3t 阅读(424) 评论(0) 推荐(0)
ruby中proc和lambda的return区别
摘要:学习ruby有一段时间了,但是我看了好几遍proc和lambda的return区别的区别讲解,始终没明白到底什么区别,今天上午又看,终于感觉是茅塞顿开有点领悟了 一下内容部分来自<<ruby元编程>>第二版92页 1 lambda中的return表示仅仅才从,这个lambda中返回,那么从lambd 阅读全文
posted @ 2016-10-17 12:52 c3tc3tc3t 阅读(242) 评论(0) 推荐(0)
ruby formatting time
摘要:%Y%m%d => 20071119 Calendar date (basic) %F => 2007-11-19 Calendar date (extended) %Y-%m => 2007-11 Calendar date,... 阅读全文
posted @ 2016-09-29 16:30 c3tc3tc3t 阅读(221) 评论(0) 推荐(0)
rails4.2.6配置发送邮件
摘要:调试了很久,最后终于可以发送了 1 在config/environments/development.rb文件里配置邮件信息 config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method 阅读全文
posted @ 2016-07-04 13:18 c3tc3tc3t 阅读(219) 评论(0) 推荐(0)
rails 配置使用mysql
摘要:1 在gemfile中要添加 gem 'mysql2' 2 在mysql数据库中创建三个数据库 dept_dev dept_test dept_pro 3 配置文件 阅读全文
posted @ 2016-06-25 10:03 c3tc3tc3t 阅读(606) 评论(0) 推荐(0)
rails中两种回滚-reversible和revert区别【更新】
摘要:1 通常迁移内容写在change方法中 ,但是有些迁移内容不能自动通过执行rake:rollback回滚, 所以在迁移文件里要使用 reversible 方法,告诉rails如何回滚例如下面 # coding: utf-8 class ExampleMigration < ActiveRecord: 阅读全文
posted @ 2016-06-17 16:03 c3tc3tc3t 阅读(700) 评论(0) 推荐(0)
脱离rails 使用Active Record
摘要:目录结构 database.yml 001_schema.rb customer.rb ar.rb Gemfile Rakefile 使用说明 在程序目录先执行 bundle install 1 在ruby目录执行 命令: 2 在ruby目录创建 active_record.rb 我在rubymin 阅读全文
posted @ 2016-06-15 14:43 c3tc3tc3t 阅读(254) 评论(0) 推荐(0)
.nil? .empty? .blank? .present? in Ruby on Rails
摘要:1 We get confused when there are many options to choose from. Same is the case when it comes to use any one from the above list. But one needs to be careful in using them and it is better that we un... 阅读全文
posted @ 2016-06-06 16:58 c3tc3tc3t 阅读(222) 评论(0) 推荐(0)
ruby关于flip-flop理解上一个注意点
摘要:上面的flip-flop的用法,你可以理解成 将 大于等于5和小于等于10的数字打印出来,也就是理解成 puts x if x >=5 && x <=10 ,但是注意你不能写成下面这样 如果写成绿色背景的代码,就会造成输出 大于等于5 小于等于20的数字 问题2 flip-flop的用法 在普通的判 阅读全文
posted @ 2016-05-18 11:11 c3tc3tc3t 阅读(347) 评论(0) 推荐(0)
ruby 使用Struct场景
摘要:替代类使用,节省代码,清晰简洁 使用Struct SelectOption = Struct.new(:display, :value) do def to_ary [display, value] endend option_struct = SelectOption.new("Canada (C 阅读全文
posted @ 2016-05-15 17:02 c3tc3tc3t 阅读(325) 评论(0) 推荐(0)
Opensturt和Struct区别
摘要:1 OpenStruct和Struct区别,Opestruct你需要创建时,直接给属性赋值,而Struct需要先定义属性后 ,再给属性赋值。选择哪个就看你对属性赋值的时机, 2 Struct和Opensturt表示的属性之间关系比hash更紧密一些。但是他们没有作为类的实例方法,一组可选的函数,如果 阅读全文
posted @ 2016-05-15 16:15 c3tc3tc3t 阅读(318) 评论(0) 推荐(0)
ruby4种比较符号
摘要:The == comparison checks whether two values are equal eql? checks if two values are equal and of the same type equal? checks if two things are one and 阅读全文
posted @ 2016-05-14 22:53 c3tc3tc3t 阅读(181) 评论(0) 推荐(0)
ruby迭代器枚举器
摘要:迭代器一个迭代器是一个方法,这个方法里面有yield语句,使用了yield的方法叫做迭代器,迭代器并非一定要迭代,与传递给这个方法的块进行数据传输 yield将数据传给代码快,代码块再把数据传输给yield each方法就是一个迭代器,里面有yield语句 枚举器1 一个枚举器是Enumerable 阅读全文
posted @ 2016-05-11 17:49 c3tc3tc3t 阅读(253) 评论(0) 推荐(0)
ruby的optparse使用小记
摘要:使用小记 阅读全文
posted @ 2016-03-18 13:59 c3tc3tc3t 阅读(1055) 评论(0) 推荐(0)
RSpec自定义matcher
摘要:链接 https://relishapp.com/rspec/rspec-expectations/v/3-4/docs/custom-matchers/define-a-custom-matcher#define-aliases-for-your-matcher 1 require 'rspec/ 阅读全文
posted @ 2016-03-03 18:55 c3tc3tc3t 阅读(272) 评论(0) 推荐(0)
What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
摘要:http://stackoverflow.com/questions/998979/difference-between-and-in-rails/25617607#25617607 http://stackoverflow.com/questions/7996695/what-is-the-dif 阅读全文
posted @ 2016-02-26 23:45 c3tc3tc3t 阅读(266) 评论(0) 推荐(0)
yield self和instance_eval用法区别
摘要:class Foo def initialize(&block) instance_eval(&block) if block_given? end end class Foo def initialize yield self if block_given? end end x = Foo.new 阅读全文
posted @ 2016-02-26 20:41 c3tc3tc3t 阅读(304) 评论(0) 推荐(0)
行为驱动开发学习心得(一)
摘要:最近在看《The Rspec Book》这本书,主要讲的就是行为驱动开发,先不说这种方式的优劣,通过我看了前2章,觉得这种开发方式目前解决了我以前遇到的问题 一 业务分析需求了解的情况 问题 1 口口相传 我以前做开发,需要和产品经理或者项目分析人员,反复交流 ,首先我先听产品经理和分析人员描述需求 阅读全文
posted @ 2016-02-11 12:04 c3tc3tc3t 阅读(748) 评论(0) 推荐(0)
Rspec中describe和context不同
摘要:转自 http://lmws.net/describe-vs-context-in-rspec 学习rspec,不太理解describe和context。google了一下,找到这篇文章,感觉说的有些道理 1 在Rspec的世界里,我们经常看到人们使用descirbe代码块和context代码块 例 阅读全文
posted @ 2016-02-10 16:55 c3tc3tc3t 阅读(1139) 评论(0) 推荐(0)
Enumerator yielder.yield 与 Proc.yield 区别
摘要:最近看ruby cookbook遇到这个用法,google一下,这里原文解释http://stackoverflow.com/questions/18865860/enumerator-yielder-yield-vs-proc-yieldEnumerator yielder.yield VS Pr... 阅读全文
posted @ 2016-01-09 15:15 c3tc3tc3t 阅读(258) 评论(0) 推荐(0)

上一页 1 2 3 下一页