DEV Community

Cover image for Alright on to ruby and boy oh boy!?!?
danielarmbruster0314
danielarmbruster0314

Posted on

Alright on to ruby and boy oh boy!?!?

Today in the curriculum of my bootcamp they were introducing the concept of require and require_relative. However the example they used had classes and so I did some digging and are ruby classes somewhat similar or conceptually close to react components? I mean you build it so that when it is passed data it builds an object and in react you pass a component data to create DOM elements. Is this conclusion accurate? Are they both modular?

Latest comments (4)

Collapse
 
jeremyf profile image
Jeremy Friesen

They are somewhat similar, but I'd hold that very lightly.

A Ruby class defines how you construct an instance of the class (via the initialize, though that's a short-hand for what's fully happening, but that's a tangent).

An instance of a class encapsulate's the object's data and its methods are used to interact with the instance. All of this is similar to what's in the object-oriented languages (Javascript can emulate this with prototypes…kind of).

Collapse
 
danielarmbruster0314 profile image
danielarmbruster0314

That makes a lot more sense. Similarly in the sense that is a modular design however is a object module verse the JavaScript emulation of modulization of model (components). Ruby's class is an abstraction of data, and JavaScript(react) component is the DOM representation of data. This was very helpful ty.

Collapse
 
gumatias profile image
Gustavo Matias • Edited

I think you're on the right track.

You're correct when it comes to the concept of "building something from almost nothing" or "a template that itself has no real value yet". So you have a "thing" that you can create something more concrete out of it. Or less abstract.

For example, in Ruby you could go to your IRB console and create an object by entering BasicObject.new. You didn't really pass any actual data and it wouldn't give you anything really substantial. But still you got yourself one object built out of a class.

React components too can be a simple as having not much. Like an empty string or a <div/> that you don't need to pass anything in order to build it. But still you got something more concrete that you can play with somewhere.

Hopefully that made more sense rather than confuse you more :)

Collapse
 
danielarmbruster0314 profile image
danielarmbruster0314

I think I understood, a react component is a more flexible peace of modular data at base creation making it easier to manipulate when compared to ruby object(Hash). Ty