Mixins

Started by Seox, June 17, 2009, 04:47:36 pm

Previous topic - Next topic

Blizzard

Yeah. I made some kind of textual RPG engine for two players fighting each other in QBasic. The code sucked major ass (1500 lines I think). I also did some small select-a-choice adventures where you are trying to find some big treasure and mostly end up dying. I don't usually mention it since it wasn't really critical to learning how to code because I had forgotten most of it until college.

@WcW: Also:

Quote from: Blizzard on June 18, 2009, 04:13:19 am
4. The ONLY mixins that makes sense are modules like Enumerable and Comparable. And even those can be coded better without the module.


Well, they might not be coded better without the module. But then again, it all depends.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

I started in RMXP at 12. I really, really sucked though, mainly because I was never willing to stop and learn, just play around with scripts all the time. :(

Ryex

June 18, 2009, 02:20:23 pm #22 Last Edit: June 18, 2009, 02:22:07 pm by Ryexander
I started when i was 14 too I'm 17 now.

aaah static classes! that is what they're called!
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

fugibo

There's a 9-year-old somewhere in Africa with a MS IT license thingy.

Also, split-topic-time?

Seox

Meh. Blizz'd know.


So, aren't static classes pretty much ANY module? Since they're never instanciated? I'm sure there's more criteria than that, but not sure as to what. Are they stand alone, in that they're not just a bunch of attributes for mixing in? (Random tangent: I don't see the point of class methods, and modules have some of their own. What exactly is the difference between instance and class methods? I know that they're called Class.method, or similar, but not why they're different.)


Thanks for tolerating me, XD!
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

Class methods == purely organizational purposes. Class methods/variables are so that you can organize code relating to a class within the class itself.

Seox

Quote from: Longfellow on June 18, 2009, 03:08:05 pm
Class methods == purely organizational purposes. Class methods/variables are so that you can organize code relating to a class within the class itself.


May I please have an example? I usually understand underlying concepts very well, but not the application of those same concepts until I have a tangible example to study.

Please and thank you ^_^
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

Look at File, IO, Time, etc in the standard library.

Also, what resource/resources are you using? It sounds as if you're using a book or something (or maybe Pragmatic Programmers?)

Blizzard

Class variables and methods can be called without instantiating the class. In other words as if the class was a module. They are practically static methods and they are the same for one class and all instances of that class. Instance variables and methods become available once you instantiate an object. Each object has its own instance variables.

class A
  @@common = 1
  def self.show_class
    p @@common
  end
  def set2
    @test = 2
  end
  def set3
    @test = 3
  end
  def mess_up(x)
    @@common = x
  end
  def show
    p @test
  end
end

a1 = A.new
a2 = A.new
a1.set2
a2.set3
a1.show # 2
a2.show # 3
A.show_class # 1
a2.mess_up(7)
A.show_class # 7
a1.mess_up(5)
A.show_class # 5



And modules are all static, yes.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seox

June 19, 2009, 11:28:56 am #29 Last Edit: June 19, 2009, 11:31:02 am by Seox
Quote from: Longfellow on June 18, 2009, 04:42:15 pm
Look at File, IO, Time, etc in the standard library.

Also, what resource/resources are you using? It sounds as if you're using a book or something (or maybe Pragmatic Programmers?)



O_o. How'd you guess that I was using a book? No, not pragmatic. I didn't have $50 >.>. I just got some $35 one, but will prolly "upgrade" for my birthday (wednesday, W00t!). I've also used SEVERAL internet tuts. Ghetto, yes, but I really am learning. I just completed my game's sidearm system. It's RAWK.



Blizz, thank you for those examples ^_^. I think that clears it up!. That they were many different examples was a big factor, thanks.

... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

Blizzard

I'm going to cover that in my next e-book anyway. xD
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

The fact that you knew the word "mixin." Almost NOBODY who learns Ruby through the intrawabs knows that much about Ruby, at least not that early on (I've learned entirely through use of the 'net, but w/e)

Blizzard

I've come across it a few times early already. I didn't know how that was called until about a year or two ago.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Seox

Quote from: Longfellow on June 19, 2009, 01:37:09 pm
The fact that you knew the word "mixin." Almost NOBODY who learns Ruby through the intrawabs knows that much about Ruby, at least not that early on (I've learned entirely through use of the 'net, but w/e)


XD

Was that a compliment? ( :naughty: ) < XD

Why's poignant guide mentions it. That's the first guide that I used, but it didn't help me much. After I left here for 1-2 months, I looked at it again, and...here I am.

Meh.
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)