`

研究小计1

阅读更多
有时候对一些基础的东西,不知道它的边界在哪里,其实做些小实验就知道了.不知道其他人想过下面这样的问题没?

1.我们创建一个对象,直接保存到数据库,会是什么情况?
完整文字 id(integer) name(string) sex(string) age(integer) birthday(date) created_at(time) updated_at(time)
编辑 删除 1     NULL NULL      NULL   NULL          2011-04-19 15:32:39 2011-04-19 15:32:39

2.我们从数据库直接读出来会是什么结果呢?
#<User id: 7, name: nil, sex: nil, age: nil, birthday: nil, created_at: "2011-04-19 15:32:39", updated_at: "2011-04-19 15:32:39">

3.如果我们设置了默认值,重复上面的步骤会是什么结果呢?
完整文字 id name sex age birthday created_at         updated_at
编辑 删除 1 NULL 男 0 2011-01-31 2011-04-19 15:42:40 2011-04-19 15:42:40
#<User id: 1, name: nil, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:42:40", updated_at: "2011-04-19 15:42:40">

4.我们来做测试下的操作
测试的日志:
a.其他类型(string,integer,date,time,array,hash,nil)到string
>>u = User.new
u = User.new
=> #<User id: nil, name: nil, sex: "男", age: 0, birthday: "2011-01-31", created_at: nil, updated_at: nil>
?>u.name = "abc"
=> "abc"
>>u
=> #<User id: nil, name: "abc", sex: "男", age: 0, birthday: "2011-01-31", created_at: nil, updated_at: nil>
>>u.name = 100
=> 100
>>u
=> #<User id: nil, name: 100, sex: "男", age: 0, birthday: "2011-01-31", created_at: nil, updated_at: nil>
>>u.name.class
=> Fixnum
>>Date.now
NoMethodError: private method `now' called for Date:Class
from (irb):10
>>Date.new
=> Mon, 01 Jan -4712
>>u.name = Date.new
=> Mon, 01 Jan -4712
>>u.save
=> true
>>u
=> #<User id: 2, name: "-4712-01-01", sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:55:15">
>>u.name.class
=> Date
>>u.name = Time.now
=> Tue Apr 19 23:56:59 +0800 2011
>>u.save
=> true
>>u
=> #<User id: 2, name: "2011-04-19 23:56:59", sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:57:06">
>>u.name.class
=> Time
>>u.name = ["a","b","c"]
=> ["a", "b", "c"]
>>u.save
=> true
>>u
=> #<User id: 2, name: ["a", "b", "c"], sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:58:19">
>>u.name.class
=> Array
>>u
=> #<User id: 2, name: ["a", "b", "c"], sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:58:19">
>>u.name = {:a => "a",:b => "b",:c => "c"}
=> {:c=>"c", :a=>"a", :b=>"b"}
>>u.save
=> true
>>u
=> #<User id: 2, name: {:c=>"c", :a=>"a", :b=>"b"}, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:59:48">
>>u.name.class
=> Hash
>>u.name
=> {:c=>"c", :a=>"a", :b=>"b"}
>>u.name = nil
=> nil
>>u
=> #<User id: 2, name: nil, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 15:59:48">
>>u.save
=> true
>>u.name
=> nil
>>u.name = true
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:01:27">
>>u.name.class
=> TrueClass
b.其他类型到integer
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:01:27">
>>u.age = "abc"
=> "abc"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:06:33">
>>u.age = 12.6
=> 12.6
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 12, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:07:14">
>>u.age = Date.new
=> Mon, 01 Jan -4712
>>u.save
u.save
=> true
?>u
=> #<User id: 2, name: true, sex: "男", age: 1, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:08:17">
>>u.age = Time.now
=> Wed Apr 20 00:08:50 +0800 2011
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 1303229330, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:08:56">
>>u.age = ['a','b','c']
=> ["a", "b", "c"]
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 1, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:09:29">
>>u.age = {"a" => "aa","b" => "bb","c" => "cc"}
=> {"a"=>"aa", "b"=>"bb", "c"=>"cc"}
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 1, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:09:29">
>>u.age = nil
=> nil
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: nil, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:10:47">
>>u.age = true
=> true
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 1, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:11:13">
>>u.age = false
=> false
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-01-31", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:11:13">
c.其他类型到Date
>>u.birthday = 120
=> 120
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: nil, updated_at: "2011-04-19 16:31:49">

>>u.birthday   = "abcdef"
=> "abcdef"
>>u.birthday
u.birthday
=> nil
?>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: nil, created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:16:57">
>>u.birthday = "2011-01-25"
=> "2011-01-25"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-01-25", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:13:12">
>>u.birthday = "2011-02-25 17:28:32"
=> "2011-02-25 17:28:32"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-02-25", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:14:19">
>>u.birthday = Date.new
u.birthday = Date.new
=> Mon, 01 Jan -4712
?>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "-4712-01-01", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:15:28">
>>u.birthday = Time.now
=> Wed Apr 20 00:15:55 +0800 2011
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: "2011-04-20 00:15:55", created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:15:59">
>>u.birthday = nil
=> nil
>>u.save
u.save
=> true
?>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: nil, created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:16:57">
>>u.birthday = true
=> true
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: true, created_at: "2011-04-19 15:55:15", updated_at: "2011-04-19 16:20:33">
d.其他类型到time
>>u.created_at = "abc"
=> "abc"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: true, created_at: nil, updated_at: "2011-04-19 16:23:27">
>>u.created_at = 12
=> 12
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: true, created_at: nil, updated_at: "2011-04-19 16:23:27">
>>u.created_at = nil
=> nil
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: true, created_at: nil, updated_at: "2011-04-19 16:23:27">
>>u.created_at = true
=> true
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: true, created_at: nil, updated_at: "2011-04-19 16:23:27">
>>u.birthday = false
=> false
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: false, created_at: nil, updated_at: "2011-04-19 16:30:37">
>>u.created_at = "2011-01-25"
=> "2011-01-25"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: "2011-01-25 00:00:00", updated_at: "2011-04-19 16:32:28">
>>u.created_at = "2011-02-25 17:28:32"
=> "2011-02-25 17:28:32"
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: "2011-02-25 17:28:32", updated_at: "2011-04-19 16:32:51">
>>u.created_at = Date.new
=> Mon, 01 Jan -4712
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: "-4713-12-31 16:00:00", updated_at: "2011-04-19 16:33:15">
>>u.created_at = Time.now
=> Wed Apr 20 00:33:30 +0800 2011
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: "2011-04-19 16:33:30", updated_at: "2011-04-19 16:33:40">
>>u.created_at = nil
=> nil
>>u.save
=> true
>>u
=> #<User id: 2, name: true, sex: "男", age: 0, birthday: 120, created_at: nil, updated_at: "2011-04-19 16:34:29">
分享到:
评论

相关推荐

    分光计测最小偏向角法内容的延伸及数据处理的改进研究.pdf

    本篇研究文献主要讨论了分光计测量最小偏向角的实验原理以及在数据处理方面的改进。研究中指出,传统的实验方法存在一些不足,例如,在使用等边三棱镜时,找到最小偏向角的位置较为容易,但实际科研和实验中常用的...

    小计天空源码

    "小计天空源码"是一个基于ASP...通过研究"小计天空源码",开发者可以学习到如何构建和维护一个ASP网站,理解服务器端脚本的工作原理,以及如何与数据库进行交互。同时,对于ASP的实践经验和技能提升也是非常有帮助的。

    用分光光度计预测小球藻藻液的浓度

    在现代生物技术研究中,小球藻因其快速的生长速度、较高的营养价值以及易于培养的特性,成为了研究的焦点之一。小球藻(Chlorella vulgaris Beij)属于绿藻门、绿藻纲、绿球藻目、卵囊藻科、小球藻属。其细胞内富含...

    基于单片机的泵缸复合动态流量计的研究

    算机的重要分支,单片机体积小,功能强大,价格低廉,使用方便,发展迅速,在 工业生产中得到了广泛的应用。 有鉴于此,本文将利用微电子技术对泵缸复合流量计样机的测试系统进行改进, 利用单片机对无载液压缸两测...

    小计天空黑白版 v2.03

    标题“小计天空黑白版 v2.03”暗示我们正在处理一个名为“小计天空”的软件或应用程序的特定版本,即v2.03,它可能是以黑白风格设计的。这种版本通常代表着软件的更新迭代,可能包含了性能优化、新功能的添加或者...

    可芯片化的激光抽运Mz型原子磁强计参数研究.pdf

    描述中的知识点:从描述中可得知,激光抽运型原子磁强计相较于传统磁强计有体积小、功耗低及灵敏度高的优势。工作原理部分阐述了激光抽运Mz型原子磁强计的操作方式,包括激光功率和射频场强度对磁共振信号的影响。...

    论文研究-计及噪声影响的介损角测量方法研究 .pdf

    噪声的存在很容易掩盖实际的介损角,尤其是在介损角较小的情况下。为此,本文提出了一种基于离散频谱对称插值算法来计算电压和电流的基波相位角,进而通过电压与电流基波相位差来实现介损角的测量。 除此之外,为...

    小计天空 v5.07 紫色恋人

    【小计天空 v5.07 紫色恋人】是一款专为女性用户设计的个人主页模板,它的核心特点是采用了紫色作为主色调,营造出一种既优雅又不失童真的氛围,展现出独特的美感和高雅气质。这款个人主页设计充分考虑了女性用户的...

    涡街流量计信号处理方法与系统的研究现状

    ### 涡街流量计信号处理方法与系统的研究现状 #### 一、引言 涡街流量计是一种基于流体振动原理的新型流量计,自20世纪60年代末期发展以来,因其独特的设计原理及诸多优势,在工业流量测量领域得到了广泛应用。其...

    石英振梁加速度计的小波神经网络温度补偿研究.pdf

    《石英振梁加速度计的小波神经网络温度补偿研究》这篇文章主要探讨了在捷联惯导系统中,石英振梁加速度计由于温度变化导致的输出漂移问题,并提出了利用小波神经网络进行温度补偿的技术方案。文章首先指出了石英振梁...

    低功率LED光源的小型分布式光色度计研究.pdf

    《低功率LED光源的小型分布式光色度计研究》是一篇关于照明工程学报的文章,主要探讨了针对低功率LED光源的新型测量设备——小型分布式光色度计的设计与应用。该设备能够同步快速地测量空间光度和色度分布,具有场地...

    低功耗涡街流量计研究

    涡街流量计因其介质适应性强、无可动部件、结构简单、可靠性高、压力损失小、使用寿命长等优点,在众多行业获得了广泛应用。然而,在低流速和管道振动条件下,涡街流量计易受噪声影响,测量精度和量程比受到限制。...

    非集计模型及其应用研究

    非集计方法直接利用调查得到的个人数据来构造模型,其样本容量相对较小,不需要对个人原始资料进行复杂的处理。而集计方法则是以交通分区为研究单位,将分区内的个人或家庭调查数据进行统计处理,如求平均值、求比例...

    基于激光测距仪与里程计融合定位技术的变电站智能巡检机器人研究.pdf

    本文探讨了基于激光测距仪与里程计融合定位技术的变电站智能巡检机器人的研究,涉及了智能巡检机器人在变电站巡检工作中的定位技术,并对其可行性进行了研究。在变电站巡检机器人中,定位功能是实现机器人智能巡检的...

    小计天空快递跟踪系统 v1.04

    "小计天空快递跟踪系统 v1.04"是一款专为快递公司设计的跟踪系统,旨在提高物流行业的服务质量和效率。这款系统的核心功能是让快递公司能够通过专业的输单人员输入快件信息,随后客户就能在线实时查询他们的包裹状态...

    论文研究-低功耗高精度光功率计设计 .pdf

    当前市场上的光功率计存在价格高和精度低的问题,为此陈卓、吴巍两位研究人员提出了一种新的设计方案,旨在提高测量精度的同时大幅度降低功耗。 设计方案中提出了多种技术要点,包括了AD转换器、单片机模块、ICL...

    计及分布式电源的配电网储能配置研究.pdf

    计及分布式电源的配电网储能配置研究 本研究探讨了分布式电源对配电网的影响,并分析了储能装置对配电网的影响。为确保配电网的安全运行,需要配置相应的储能装置。通过建立多目标函数模型,考虑了配电网节点电压...

Global site tag (gtag.js) - Google Analytics