Filter
Exclude
Time range
-
Near
30 Sep 2025
Replying to @RealBenjizo
It prints 30 because instance_method() is called on the obj instance, which changes the value of the num attribute from 10 to 30 right before it's printed.
1
2
50
Replying to @RealBenjizo
30 1.) MyClass is defined and takes 1 parameter self.num which is set to 30 in instance_method 2.) instance_method returns 30 (but does not store) 3.) obj = MyClass(10) so obj.num == 10 4.) Now instance_method is called & overwrites 10 with 30 and returns 30
2
56
Replying to @RealBenjizo
The answer is 30. In OOP, objects have state (attributes like num). obj.num starts at 10, then instance_method changes it to 30. For beginners: self refers to "this specific object." self.num = 30 means "change this object's num to 30, not all objects of this class." Each instance has its own state.
1
17
336
current value of the num instance attribute of the obj object. Since instance_method() modified obj.num to 30, this is the value that will be printed.
1
2
27
attribute for that specific instance (obj) to 30. The return f"{self.num}" line inside instance_method returns the string "30", but this returned value is not captured or used in the main part of the script. Printing obj.num: print(obj.num) then prints the
1
2
29
Replying to @RealBenjizo
The Python code outputs 30 because the instance_method called on the obj object explicitly reassigns self.num (which refers to obj.num) to 30, overriding its initial value of 10 before print(obj.num) is executed.
2
103
1 Nov 2023
Replying to @RealBenjizo
A . 30 Python code creates a class named MyClass with an instance method named instance_method. The __init__ method initializes the instance variable my_var with the value passed to it. The instance_method method sets the value of my_var to 30 and returns it. When you run this code, it will output 30. This is because the instance_method method sets the value of my_var to 30 and returns it. The print statement then prints the value of my_var, which is now 30.
4
1,237
Replying to @RealBenjizo
Answer A). 30 👉Let's break down the code and understand its output step by step. 1. Class Definition: The code begins with the definition of a class named `MyClass`. Inside the class, we have three methods - `*init*`, `instance_method`, and the `print` statement.
1
1
6
641
included で instance_method(false) で取れたやつを全部 define_method するとか。邪悪。
1
2
6
504
6 Mar 2023
Rubyの instance_method、継承メソッドも取得対象なのは実用的には便利そうなのだけれども、レシーバに定義されている現物だけを想定しているとファッ?ってなるので、instance_methods みたいに第二引数で inherited_too を指定できた方がよかったかも…と少し思った^^;

5 Mar 2023
「静的な呼び出し」とは?ってなっている^^; >静的メソッドは静的にしか呼び出せないメソッド(Rubyでいうクラスメソッド)ではありません。 念のため、元文脈では「クラスからしか呼び出せない」という意味で書いていると思います Ruby ideone.com/hQWntU Smalltalk ideone.com/bLXOCn
1
2
1,387
21 Feb 2023
Replying to @RealBenjizo
A) 30 because first MyClass(10) will instantiate num to 10. But when method instance_method() will called that will result in overwriting the num to 30.
2
137
18 Feb 2023
Replying to @RealBenjizo
Answer is 30(A) self.num was initially 10 but the instance_method re-initialized it to 30. So 30 👏👏
1
2
205
Replying to @RealBenjizo
Answer is A:30. The instance_method was called after initialising with the value 10.
1
8
1,199
Replying to @RealBenjizo
this should give 30 because the instance_method is being called which has its num value set to 30.
1
4
1,592
Something like instance_method(__method__).supermethod
6
クラスメソッドを FooClass.class_method, インスタンスメソッドを FooClass#instance_method って表現する慣習って時に便利なのだけど、 Ruby 方面でしか普及してないのだろうか。代替でもいいから普及している表現方法ないだろうか。
2
2
14 Jan 2022
#これを見たフォロワーさんはアカウント名の由来を言う Instance_Method プログラミング用語。 名前に困り、プログラミングをしていた時に「これ語呂いいんじゃね?」ってなって採用。
3
29 Dec 2020
Replying to @avdi
You forgot to hashtag this tweet with #instance_method
2
Module#instance_methodまでカバーしようとすると辛い。 :::が空いてるかな?
1