易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Ruby

ruby在windows 7 cmd 中显示彩色文字

先放上一个实例的bat文件,要求管理员特权运行:
@echo off
::CMD里显示彩色文字
chcp 437>nul&&graftabl 936>nul
if not exist CONFIG.NT copy %WinDir%\System32\CONFIG.NT CONFIG.NT
@cls
echo DEVICE=%WinDir%\System32\ANSI.SYS /x >%WinDir%\System32\CONFIG.NT
@echo.
command /cecho 
command /cecho hello world
command /cecho  登鹳雀楼
@echo.
@echo.
command /cecho  白日依山尽,黄河入海流。
@echo.
command /cecho  欲穷千里目,更上一层楼。
@echo.
@echo.
@echo.
@echo.
command /cecho  下江陵
@echo.
@echo.
command /cecho  朝辞白帝彩云间,千里江陵一日还。
@echo.
command /cecho  两岸猿声啼不住,轻舟已过万重山。
@echo.
@echo.
command /cecho  继续下页
pause>nul
@cls
@echo.
@echo.
@echo.
command /cecho  ......

Ruby继承 九筒一条

Ruby 类的继承
关键字: Ruby 类的继承


一、普通方式的继承
 Ruby只支持单继承
 
ruby 代码
class
 Child < Father
  

......   

end
  

    Object是所有类的始祖,并且Object的实例方法对ruby的所有对象都是可用的。
    super的使用:
         1、在initialize中使用super,将调用其父类的initialize方法
         2、在一般的实例方法中使用,将调用其父类中同名的方法。
   向一个对象发送调用方法时,ruby的本质过程如下:
         1、ruby将检查该对象所属的类,如果该类实现了该方法,就运行该方法
         2、如果该类没有实现该方法,ruby将找到其直接父类中的方法,然后是其祖父类,凡此以往追溯整个祖先链
         3、如果最终没有找到合适方法,ruby会产生一个特殊的 ......

RUBY实践—带密码加密的用户创建及修改

开发环境
Ruby: Ruby1.9.1
Rails: Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
一、创建数据表Users
利用RubyMine自带的Scaffold工具创建数据表Users,也可以手动创建
二、创建Controller和View
Ruby项目—>右键—>Create Model
完成后将自动生成相应的文件
三、修改Model user.rb
利用Digest/SHA1对密码进行加密,实现加密保存
修改后代码如下:
require "digest/sha1"
class User < ActiveRecord::Base
attr_accessor :hashed_password,:repassword
attr_accessible :username, :hashed_password, :repassword
validates_uniqueness_of :username
validates_presence_of :username, :hashed_password
def before_create
self.password = User.hash_password(self.hashed_password)
end
def after_create
@hashed_password = nil
end
def before_update
self.password = User.hash_password(self.hashed_password)
end
def after_update
@hashed_password = nil
end
private
def self.hash_password(hashed_password)
Digest ......

Ruby实践—用户登录

开发环境
Ruby:Ruby1.9.1
Rails:Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
一、创建View/login
在View/login下创建login.html.erb、index.html.erb、loginFail.html.erb
login.html.erb代码如下:
<h1>Welcome to login!</h1>
<% form_tag do %>
<table>
<tr>
<td>User name:</td>
<td><%= text_field("user", "username") %></td>
</tr>
<tr>
<td>Password:</td>
<td><%= password_field("user", "hashed_password") %></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" login " /> <input type="reset" value=" reset " /></td>
</tr>
</table>
<% end %>

index.html.erb代码如下:
<h1>Choose a page to look!</h1>
<p><%= link_to 'Users', :controller=>"users",:action=>"in ......

Use lambda in Ruby 九筒一条

http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Understanding Ruby Blocks, Procs and Lambdas
Blocks, Procs and lambdas (referred to as closures
in Computer Science) are one of the most powerful aspects of Ruby, and
also one of the most misunderstood. This is probably because Ruby
handles closures in a rather unique way. Making things more complicated
is that Ruby has four different ways of using closures, each of which is
a tad bit different, and sometimes nonsensical. There are quite a few
sites with some very good information about how closures work within
Ruby. But I have yet to find a good, definitive guide out there.
Hopefully, this tutorial becomes just that.
First Up, Blocks
The most common, easiest and arguably most “Ruby like” way to use
closures in Ruby is with blocks. They have the following familiar
syntax:
array
=
[
1
,
2
,
3
,
4
]

array
.
collect!
do
|
n
|
n
**
......

Watir 语法(Web Application Testing in Ruby)

Watir 语法(Web Application Testing in Ruby)
# watir的安装
watie的安装请查看 -> Ruby library的安装
# 使用Watir工具,需要在脚本中加上
require 'watir'
# 创建一个IE的实例
ie = Watir::IE.new
或者在创建的同时直接转到页面
ie = Watir::IE.start('http://www.text.com/')
Watir使用start方法同时创建一个浏览器实例并转到一个页面。
IE浏览速度
ie.speed = :fast
ie.speed = :slow
# 页面导航
ie.goto('http://www.text.com/')
注: ie.goto还可以运行javascript的代码如: ie.goto("javascript: ie.document.write("Hello World");")
# 取得当前网页的网址
ie.url
# 点击超链接
ie.link(:text , "Pickaxe").click
ie.link(:href, /http:\/\/pragmaticprogrammer\.com/).click
ie.link(:name => 'foo', :index => 1).click
# 超链接的uri
ie.link(:text , "Pickaxe").href
ie.link(:index, 1).href
ie.link(:text => "reply", :index => 2).href
# 超链接的文本
ie.link(:href , /http:\/\/pragmaticprogrammer\.com/).text
对应的HTML代码为:
<a href='http://pragmaticprogrammer.com ......
总记录数:146; 总页数:25; 每页6 条; 首页 上一页 [1] [2] [3] [4] 5 [6] [7] [8] [9] [10]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号