Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance variables that start with `@_` [closed]

Tags:

ruby

What is the purpose of making instance variables start with an underscore like the following?

@_variables_name
like image 418
anyavacy Avatar asked Aug 17 '26 18:08

anyavacy


1 Answers

Ruby does not have a special interpretation of instance variables that start with an underscore, like PHP has a special meaning for vars that start and end with double underscores (e.g. __FILE__).

So, @_instance_var has no special meaning. Rails internally uses it to distinguish private/protected variables that other should not modify/access.

But, there is no community-wide convention yet. So, you can use the Rail's convention or make up your own use for that.

like image 83
Uzbekjon Avatar answered Aug 19 '26 11:08

Uzbekjon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!