Class: Object

Inherits:
BasicObject
Defined in:
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb,
lib/el4r/el4r-sub.rb

Overview

__funcall

Instance Method Summary collapse

Instance Method Details

#__funcall(meth, *args, &block) ⇒ Object

Call a method even if it is private.



947
948
949
950
# File 'lib/el4r/el4r-sub.rb', line 947

def __funcall(meth, *args, &block)
  m = method(meth)
  instance_eval { m.call(*args, &block) }
end

#ev(str) ⇒ Object

eval and print



33
34
35
# File 'lib/el4r/el4r-sub.rb', line 33

def ev(str)
  puts "#{str} = #{eval str}"
end

#must(*args) ⇒ Object

Assert: type === obj ex. obj.must Fixnum, Float

Raises:

  • (TypeError)


781
782
783
784
# File 'lib/el4r/el4r-sub.rb', line 781

def must( *args )
  args.each {|c| return self if c === self }
  raise TypeError, "wrong arg type '#{self.class}' for required #{args.join('/')}"
end

#must_be(obj) ⇒ Object

Assert: self == obj



800
801
802
803
804
# File 'lib/el4r/el4r-sub.rb', line 800

def must_be( obj )
  self == obj or
          raise ArgumentError, "expected #{obj.inspect} but is #{inspect}"
  self
end

#must_existObject

Assert: self != nil



807
808
809
# File 'lib/el4r/el4r-sub.rb', line 807

def must_exist
  nil? and raise ArgumentError, 'receiver is wrongly nil'
end

#must_have(*args) ⇒ Object Also known as: needed

Assert: obj.respond_to? meth ex. obj.must_have :read, :readlines ex. obj.needed :read, :readlines



789
790
791
792
793
794
795
# File 'lib/el4r/el4r-sub.rb', line 789

def must_have( *args )
  args.each do |m|
    self.respond_to? m or
        raise ArgumentError, "receiver #{inspect} does not have '#{m}'"
  end
  self
end

#nonempty?Boolean

Is self non-nil and not-empty.

Returns:

  • (Boolean)


132
133
134
135
136
# File 'lib/el4r/el4r-sub.rb', line 132

def nonempty?
  if self and !self.empty?
    self
  end
end

#pr(msg = nil) ⇒ Object

puts MSG = self.inspect for debug.



13
14
15
16
17
18
19
20
21
# File 'lib/el4r/el4r-sub.rb', line 13

def pr(msg=nil)
  if msg then
    print "#{msg} = "
  end

  display
  print "\n"
  self
end

#readf(filename) ⇒ Object

Same as File.read. But FILENAME is expanded.



579
580
581
# File 'lib/el4r/el4r-sub.rb', line 579

def readf(filename)
  File.read( File.expand_path(filename.to_s) )
end

#set_attr(ivar_name, init_value) ⇒ Object

Defines a singleton attribute. for testing purpose.



271
272
273
274
# File 'lib/el4r/el4r-sub.rb', line 271

def set_attr(ivar_name, init_value)
  eval("class << self; attr_accessor :#{ivar_name} end")
  self.instance_variable_set("@#{ivar_name}", init_value)
end

#unproc(*x) ⇒ Object



886
887
888
# File 'lib/el4r/el4r-sub.rb', line 886

def unproc(*x)
  self
end

#vpr(msg = nil) ⇒ Object

pr when $VERBOSE



24
25
26
27
28
29
30
# File 'lib/el4r/el4r-sub.rb', line 24

def vpr(msg=nil)
  if $VERBOSE then
    self.pr msg
  else
    self
  end
end

#writef(filename) ⇒ Object

Write an object’s string form. FILENAME is expanded.



584
585
586
# File 'lib/el4r/el4r-sub.rb', line 584

def writef(filename)
  open(File.expand_path(filename.to_s), "w"){|f| f.write(self.to_s)}
end