ITeye博客

简单就是美

biyeah · 共 49 篇文章

[转]Ruby中的Rake任务详述

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1683808 Rake简介 Rake和Make及Ant Rake的意思是Ruby Make,一个用ruby开发的代码构建工具。Rake的英文意思是耙子,一种很朴实的劳动工具。真的是很贴切,Rake正是一个功能强大、勤勤恳恳的劳动工具。 但是,为什么Ruby需要Rake? Ruby代码不需要编译,为什么需要Rake?其实,与其说Rake是一个代码构建工具,不如说Rake是一个任务管理工具,通过Rake我们可以得到两个好处: 以任务的方式创建和运行脚本 当然,你可以用脚本来创建每一…

2011-12-29 03:47 · Ruby · 评论(0)

[转]ruby中的闭包

原文: http://kenbeit.com/posts/87/ruby%E4%B8%AD%E7%9A%84%E9%97%AD%E5%8C%85 感谢作者的辛勤劳动。 # CLOSURES IN RUBY Paul Cantrell http://innig.net # Email: username "cantrell", domain name "pobox.com" # # 翻译: kenshin54 http://kenbeit.com # I recommend executing this file, then reading it alongside its output. #…

2011-12-26 10:42 · Ruby · 评论(0)

发发牢骚,关于iteye论坛规则小测验

今天想在论坛回复个帖子,一看自己是新手,还不能回贴,需要完成论坛规则小测验,一点进去看,乖乖,里面有13道题目,大概看了下,如果要完成至少7、8分钟吧,真是抓狂。原来的回贴热情被打了回去,呵呵,算了吧,我也不想完成这个无聊的测验,以后当个潜水员吧,这个博客就当是学习的笔记。

2011-12-25 14:03 · 综合 · 评论(0)

javascript进阶1

参考: http://ejohn.org/apps/learn 答案在后面。 1、看下面的例子,能看得出输出什么? var a = 5; function runMe(a){ console.log("a = " + a);//a=? function innerRun(){ console.log("b = " + b);//b=? console.log("c = " + c);//c=? } var b = 7; innerRun(); var c = 8; } runMe(6); for ( var d = 0; d < 3; d++ ) { setTimeout(function(…

2011-12-23 05:10 · javascript · 评论(0)

javascript回函数的几种调用方法

先来看下基本的知识,对于一个函数的调用,方法有以下几种。 //下面的几种写法是等价的。 alert('something'); this.alert('something'); alert.call(this,'something'); alert.apply(this,['something']); 以实现数组中each的方法做为例子。 第一种方式: Array.prototype.each = function(callback){ for(var i = 0; i< this.length;i++){ callback(this[i]);//参数既为函数名,直接加括号调用。 } } […

2011-12-22 04:39 · javascript · 评论(0)

coffeescript+prototypejs使编写nodejs更象ruby-like

首先安装prototype for nodejs npm install prototype 看个例子 prototype = require 'prototype' Object.extend global, prototype (9).times (x)-> console.log x [1,2,3,4].each (x)-> console.log x Person = Class.create #定义一个类 initialize: (name)-> @name = name say: (message)-> "#{@name}:#{message}" Pirate = Class.c…

2011-12-21 12:01 · nodejs · coffeescript · 评论(0)

javascript中的bind

http://www.prototypejs.org/api/function/bind In JavaScript, functions are executed in a specific context (often referred to as “scope”). Inside the function the this keyword becomes a reference to that scope . Since every function is in fact a property of some object—global functions are properties…

2011-12-21 04:08 · javascript · 评论(0)

ruby中实现闭包

ruby中实现闭包很简单 如果一个方法中返回一个procedure那就构成了一个闭包。 def func x = 0 ->{x += 1 ; p x} end proc = func proc[] #or proc.call() proc[] 输出: 1 2

2011-12-20 09:10 · Ruby · 评论(0)

排序算法(javascript版与ruby版)

排序算法(javascript版与ruby版) 合并排序 javascript版本: function merge(left, right){ var result = []; while (left.length > 0 && right.length > 0){ if (left[0] < right[0]){ result.push(left.shift());//把最小的最先取出,放到结果集中 } else { result.push(right.shift()); } } return result.concat(left).concat(right);//剩下的就是合并,这样就排…

2011-12-20 06:04 · 综合 · 评论(0)

ruby中星号的使用

ruby中星号的使用 1、数字乘法 2 * 3 = 6 2、幂 10**2 = 100 (星号之间不能有空格) 3、字符串扩展 'foo' * 2 = 'foofoo' 4、数组的扩展 ]]*2 = ],1,2,]] 5、创建数组 *a = 1,3,"as" a = 6、数组参数传入时的前缀 a= testFun(*a) == testFun(1 , 2) != testFun() 7、还没发现..

2011-12-20 05:54 · Ruby · 评论(0)

[转]ruby的include与extend

原文 http://www.cnblogs.com/rubylouvre/archive/2010/03/31/1701813.html 作者:司徒正美 ruby提供了强大的继承机制,有关继承的方法很多。最简单就是“<<”,但还可以对要继承的东西进行细分,是把它添加到类中呢,还是实例中,这正是本文要介绍的内容。 module Foo def foo puts 'heyyyyoooo!' end end class Bar include Foo end Bar.new.foo # heyyyyoooo! Bar.foo # NoMethodError: undefined method ‘f…

2011-12-20 05:09 · Ruby · 评论(0)

[转]Ruby常用的内部变量

Ruby常用的内部变量 原文 http://www.cnblogs.com/rubylouvre/archive/2009/07/23/1529237.html 作者:司徒正美 在ruby程序中,经常会看到一些以$开头的变量,这些不是指我们自己在程序中设置的全局变量,而是指系统内部已经设置好的变量,他们代表了一些特定的意思,下面搜集了一些常用的内部变量,用一些简单的代码说明他们代表的意思: 局部域: 在某一个线程作用域内才能有效,下列也可看做是线程内的局部变量。 PS:这边讲解的几个变量都是于正则匹配相关的,正则匹配过程的代码是一样的,这里不重复输入正则表达式匹配的代码,只在第一个例子里给出…

2011-12-20 03:59 · Ruby · 评论(0)

Underscore.js与nodejs相结合

今天发现这个Underscore.js,文档说 http://documentcloud.github.com/underscore/ Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby)。 提供了许多类似ruby风格的函数,这是我所喜欢的。 看几个例子。 安装 npm install underscore 在nodes.js中测试 …

2011-12-14 11:18 · nodejs · 评论(0)

NowJS and Reconnects

NowJS and Reconnects 保留 原文http://blog.nowjs.com/ This particular feature has been highly anticipated by the NowJS community for some time. With the switch to Socket.IO 0.6.18, which now has built-in support for socket reconnecting, implementation of this feature was actually quite doable. We've tes…

2011-12-14 09:03 · nodejs · 评论(0)

Nodejs中的EventEmitter

EventEmitter是nodejs核心的一部分。很多nodejs对象继承自EventEmitter,用来处理事件,及回调。来看API中的例子 var util = require("util"); var events = require("events");//EventEmitter通过events模块来访问 function MyStream() {//新建一个类 events.EventEmitter.call(this); } util.inherits(MyStream, events.EventEmitter);//使这个类继承EventEmitter MyStream.p…

2011-12-14 04:57 · nodejs · 评论(0)