Help - Search - Members - Calendar
Full Version: Module Question
RPG RPG Revolution Forums > Scripting > Script Development and Support > RGSS2
Adrien.
If I am writing a module, is there a way to say, make the ability for a user using the class that includes this module NOT be able to use .new to inialize the class? instead use a diffrent method? Essentially I am asking to make a module where when included it makes the initalize method private

I know you can do in a class:

CODE
private

def inialize
end

public
#some other methods.



But I want the module to take away the idea of doing that and make the initialize method private.

Ideas?


Thread has been reported to be moved to vx
Zeriab
dI suggest you download standard ruby and look at Singleton.rb as that includes the feature you want. (Download version 1.8.x)
Adrien.
i dont want to make a singleton >_>

any ways need a mod to move this to vx
X-M-O
QUOTE (Adrien. @ Sep 3 2011, 11:37 PM) *
need a mod to move this to vx


Moved to RPG Maker VX by user request.
Adrien.
i reported the thread and nothing happened >_> lol. took me asking in my own thread >_> but thanks ^__^

so why would I look at the singleton pattern as it wont help much in rgss2 as rgss2 does NOT include a lot of core ruby implementations and classes.

Ya I looked at that module and decided what I want to do RGSS2 would not support how they did it. so I have to build it from the ground up >_>
Night5h4d3
You should not need to initialize a module with .new unless you were trying to set a variable as an instance of that object. Think of the cache module, to use it you use Cache.system() or Cache.picture() you don't use Cache.new.
Zeriab
So you know what a Singleton is, good ^^
Do tell me how you would implement the singleton pattern without controlling access to the new method wink.gif
Adrien.
So I am just playing with code. So forgive me if I seem retarded and stupid. I doubt this would EVER be implemented into a script.

CODE
module Sample

  class << self
    def extended klass
      klass.instance_variable_set :@instance, klass.new
      klass.private_class_method :new
    end
  end
  
  def instance
    @instance
  end
  
end


class Test
    extended Sample
end

Test.instance


I am getting the error method error no such method on .instance
How ever Test<Sample states I already have the module being used why extend it.

So why am I getting a no method error? I thought what I was doing was correct.

an update:

Test.new works when it shouldnt. in windows it throws an error, oh and this script compiles in windows and works, but not in RGSS2? um confusion?

Hell even in linux it works.

Does RGSS2 not support what I am trying to do?

edit - issue fixed

also this should thread needs to be moved to script support not VX
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.