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?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
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).
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 :)
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