Module: Ludy

Defined in:
lib/ludy.rb,
lib/ludy/lazy.rb,
lib/ludy/list.rb,
lib/ludy/dices.rb,
lib/ludy/timer.rb,
lib/ludy/variable.rb,
lib/ludy/blackhole.rb,
lib/ludy/paginator.rb,
lib/ludy/tasks/common.rb,
lib/ludy/y_combinator.rb,
lib/ludy/z_combinator.rb,
lib/ludy/deprecated/this.rb,
lib/ludy/pattern_matcher.rb,
lib/ludy/deprecated/curry.rb,
lib/ludy/deprecated/aspect.rb,
lib/ludy/deprecated/rambda.rb,
lib/ludy/helpers/check_box.rb,
lib/ludy/message_dispatcher.rb,
lib/ludy/deprecated/callstack.rb

Defined Under Namespace

Modules: CheckBox, Curry Classes: ArrayPaginator, Blackhole, DiceSet, Dices, Lazy, List, MessageDispatcher, Page, Paginator, PatternMatcher, RailsPaginator, Rambda, Timeout, Timer, Variable

Constant Summary collapse

VERSION =

:stopdoc:

'0.1.10'
LIBPATH =
::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
Y =

the Y combinator, with lazy stuff

lambda{|f|
  lambda{|x| lazy{f[x[x]]} }[lambda{|x| lazy{f[x[x]]} }]
}
Z =

the Z combinator, without lazy stuff

lambda{|f|
  lambda{|x| f[lambda{|y| x[x][y]}]}[
    lambda{|x| f[lambda{|y| x[x][y]}]}
  ]
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callstack(levels = -1) ⇒ Object

TRACE_EVENT = 0 TRACE_FILE = 1 TRACE_LINE = 2 TRACE_MSG = 3 TRACE_BINDING = 4 TRACE_CLASS = 5



10
11
12
13
# File 'lib/ludy/deprecated/callstack.rb', line 10

def callstack levels = -1
  st = Thread.current[:callstack]
  if levels then st && st[levels - 2] else st end
end

.erbout(string, binding) ⇒ Object

append erb output…



4
5
6
# File 'lib/ludy/tasks/common.rb', line 4

def self.erbout string, binding
  eval('_erbout', binding) << string
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



28
29
30
# File 'lib/ludy.rb', line 28

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



36
37
38
# File 'lib/ludy.rb', line 36

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, *args)
end

.require_all_in(dir) ⇒ Object

require all files in the dir, only work for ludy. i.e., Ludy.require_all_in ‘proc’ => require ‘ludy/proc/*.rb’



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ludy.rb', line 55

def self.require_all_in dir
  require 'rubygems' if RUBY_VERSION < '1.9.0'
  require 'rake'
  Dir.glob("#{LIBPATH}ludy/#{dir}/*.rb").each{ |i|
    require(if dir == '.'
              i.pathmap('ludy/%n')
            else
              i.pathmap("ludy/#{dir}/%n")
            end)
  }
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to rquire all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



45
46
47
48
49
50
51
# File 'lib/ludy.rb', line 45

def self.require_all_libs_relative_to( fname, dir = nil )
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '**', '*.rb'))

  Dir.glob(search_me).sort.each {|rb| require rb}
end

.thisObject



5
6
7
8
9
10
11
12
# File 'lib/ludy/deprecated/this.rb', line 5

def this
  info = callstack(-2)
  # lambda{ |*args|
    # Thread.current[:temp_args] = args
    # eval("send :#{info[3]}, *Thread.current[:temp_args]", info[4])
  # }
  eval('self', info[TRACE_BINDING]).method(info[TRACE_MSG])
end

.versionObject

Returns the version string for the library.



20
21
22
# File 'lib/ludy.rb', line 20

def self.version
  VERSION
end

Instance Method Details

#lazy(arg = nil, &block) ⇒ Object

provided for creating lazy object more convient



28
29
30
# File 'lib/ludy/lazy.rb', line 28

def lazy arg = nil, &block
  Lazy.new arg, &block
end

#rambda(&block) ⇒ Object



19
20
21
# File 'lib/ludy/deprecated/rambda.rb', line 19

def rambda &block
  Rambda.new &block
end

#var(arg) ⇒ Object

provided for creating lazy object more convient



25
26
27
# File 'lib/ludy/variable.rb', line 25

def var arg
  Variable.new arg
end