@@ -1687,6 +1687,7 @@ public PrivateInstanceMethodsNode() {
1687
1687
1688
1688
@ NodeChild (value = "module" , type = RubyNode .class )
1689
1689
@ NodeChild (value = "name" , type = RubyNode .class )
1690
+ @ NodeChild (value = "inherit" , type = RubyNode .class )
1690
1691
protected abstract static class AbstractMethodDefinedNode extends CoreMethodNode {
1691
1692
1692
1693
final Visibility visibility ;
@@ -1700,39 +1701,47 @@ protected RubyNode coerceToString(RubyNode name) {
1700
1701
return NameToJavaStringNode .create (name );
1701
1702
}
1702
1703
1703
- @ Specialization
1704
- protected boolean isMethodDefined (RubyModule module , String name ) {
1705
- // TODO (pitr-ch 30-Mar-2016): cache lookup
1706
- return ModuleOperations .lookupMethod (module , name , visibility ) != null ;
1704
+ @ CreateCast ("inherit" )
1705
+ protected RubyNode coerceToBoolean (RubyNode inherit ) {
1706
+ return BooleanCastWithDefaultNodeGen .create (true , inherit );
1707
+ }
1708
+
1709
+ // TODO (pitr-ch 30-Mar-2016): cache lookup
1710
+
1711
+ @ Specialization (guards = "inherit" )
1712
+ protected boolean isMethodDefinedInherit (RubyModule module , String name , boolean inherit ) {
1713
+ final InternalMethod method = ModuleOperations .lookupMethodUncached (module , name , null );
1714
+ return method != null && !method .isUndefined () && !method .isUnimplemented () &&
1715
+ method .getVisibility () == visibility ;
1707
1716
}
1708
1717
1718
+ @ Specialization (guards = "!inherit" )
1719
+ protected boolean isMethodDefinedDontInherit (RubyModule module , String name , boolean inherit ) {
1720
+ final InternalMethod method = module .fields .getMethod (name );
1721
+ return method != null && !method .isUndefined () && !method .isUnimplemented () &&
1722
+ method .getVisibility () == visibility ;
1723
+ }
1709
1724
}
1710
1725
1711
- @ CoreMethod (names = "public_method_defined?" , required = 1 )
1726
+ @ CoreMethod (names = "public_method_defined?" , required = 1 , optional = 1 )
1712
1727
public abstract static class PublicMethodDefinedNode extends AbstractMethodDefinedNode {
1713
-
1714
1728
public PublicMethodDefinedNode () {
1715
1729
super (Visibility .PUBLIC );
1716
1730
}
1717
-
1718
1731
}
1719
1732
1720
- @ CoreMethod (names = "protected_method_defined?" , required = 1 )
1733
+ @ CoreMethod (names = "protected_method_defined?" , required = 1 , optional = 1 )
1721
1734
public abstract static class ProtectedMethodDefinedNode extends AbstractMethodDefinedNode {
1722
-
1723
1735
public ProtectedMethodDefinedNode () {
1724
1736
super (Visibility .PROTECTED );
1725
1737
}
1726
-
1727
1738
}
1728
1739
1729
- @ CoreMethod (names = "private_method_defined?" , required = 1 )
1740
+ @ CoreMethod (names = "private_method_defined?" , required = 1 , optional = 1 )
1730
1741
public abstract static class PrivateMethodDefinedNode extends AbstractMethodDefinedNode {
1731
-
1732
1742
public PrivateMethodDefinedNode () {
1733
1743
super (Visibility .PRIVATE );
1734
1744
}
1735
-
1736
1745
}
1737
1746
1738
1747
@ CoreMethod (names = "instance_methods" , optional = 1 )
0 commit comments