#instancevariable — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #instancevariable, aggregated by home.social.
-
If you work with Ruby, you should know that arguments in methods can be set to a default value, for example:
```
def perform(arg: "d")
# .
end
```But did you know that you can use instance variables as default values, like this:
```
class MyCls
def initialize(arg); @arg = arg; end
def perform(arg = @arg); end
end
```Or other arguments of this method:
```
module MyMod
def self.perform(a = nil, arg: a); end
end
```#Ruby #Method #Default #Arguments #KeywordArguments #InstanceVariable
-
If you work with Ruby, you should know that arguments in methods can be set to a default value, for example:
```
def perform(arg: "d")
# .
end
```But did you know that you can use instance variables as default values, like this:
```
class MyCls
def initialize(arg); @arg = arg; end
def perform(arg = @arg); end
end
```Or other arguments of this method:
```
module MyMod
def self.perform(a = nil, arg: a); end
end
```#Ruby #Method #Default #Arguments #KeywordArguments #InstanceVariable
-
If you work with Ruby, you should know that arguments in methods can be set to a default value, for example:
```
def perform(arg: "d")
# .
end
```But did you know that you can use instance variables as default values, like this:
```
class MyCls
def initialize(arg); @ARG = arg; end
def perform(arg = @ARG); end
end
```Or other arguments of this method:
```
module MyMod
def self.perform(a = nil, arg: a); end
end
```#Ruby #Method #Default #Arguments #KeywordArguments #InstanceVariable