# A collection of Ruby Classes for RemoteObjects testing

module RemoteTest
require 'session_object'	# to get the SessionObject def

class Rtest
    def time
        return Time.now.to_s
    end

    def myname
        return self.class.to_s
    end

    def add2(a, b)
        return a + b
    end

    def add3(a, b, c)
        return a + b + c
    end

    def addn(*a)
        return (a.inject(0) {|sum, e| sum + e})
    end

    def concat(*s)
        return s.join(" ")
    end

    def echo(o)
        return o
    end

    def echo2(x, y)
        return x, y
    end

    def ruby_hash
        return {:sym => "symbol",
                "str" => "string",
                "num" => 987654321 }
    end

    def date(y,m,d)
        rd = Date.new(y,m,d)
        return rd.to_s
    end

    def parse_date(ds)
        da = ParseDate.parsedate(ds)
	return da
    end
end

# test attribute accessor
# can assign values with a= val, etc.,
# but cannot retrieve them later
class Stest
    attr_accessor(:a, :b, :c)
end

# test attribute accessor in a SessionObject
# can assign values with a= val, etc.,
# and can retrieve them later since this is a SessionObject
class SOtest < SessionObject
    attr_accessor(:a, :b, :c)
end

# test passing of initialization parameters to SessionObject
# controller passes a boolean init flag used to distinguish a
# real initialization from a reload to invoke methods
# the init param is only visible on the server, not on the client
class SOItest < SessionObject
    attr_accessor(:a, :b, :c)
    def initialize(init, x, y, z)
        return unless init
	# load the real initialization parameters
        @a = x
        @b = y
        @c = z
    end
end

# test invoke of Class Methods
class ClassMethods
    class << self
	def cm1
	    return "called class method cm1"
	end
    	def addn(*a)
       	    return (a.inject(0) {|sum, e| sum + e})
    	end
    end
    def im1
	return "called instance method im1"
    end
end

end #module