Class Bar
Def self.Foo1 (*args)
Do and print somethings
return result
end#Def
Def self.Foo2 (*args)
Do and print somethings
return result
end#Def
Def self.Foo3 (*args)
Do and print somethings
return result
end#Def
i want to set that the def Foo should print out only when i write
Bar.Foo1(*args).print_out and hide print with Bar.Foo1(*arg) only. Adding
one more argument is inconvenient for me (too much)
Sorry, not really sure what you're trying to do -- can you post an actual
code snippet and a test that demonstrates what you want?
···
On Mon, Jan 1, 2018 at 9:08 AM, ng khanh <cnkhanh1986@gmail.com> wrote:
i want to set that the def Foo should print out only when i write
Bar.Foo1(*args).print_out and hide print with Bar.Foo1(*arg) only. Adding
one more argument is inconvenient for me (too much)
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
hi below of my def with print_out as argument. i would like to print_out as
a method for example *self.wk_obs(wk,input,index),print_out* to get it
prints out instead input as argument because i have many similar defs like
that
thanks
def self.wk_obs(wk,input,index=0,print_out = true) # one only exact
return false unless (0..4).include?index
case index
when 0
return false unless input.is_a?String
res = wk.getObjectsByName(input)
when 1
return false unless check_idd(input)
res = wk.getObjectsByType(input.to_IddObjectType)
when 2
check = input.kind_of?(Array) ? input.all? {|x| x.kind_of?(String)} : input.
kind_of?(String)
return false unless check == true
res = wk.getObjectsByReference(input)
when 3
check = input.kind_of?(Hash) ? input.size == 1 : false
return false unless check == true
return false unless check_idd(input.keys[0])
res = wk.getObjectsByTypeAndName(input.keys[0],input.values[0])
when 4
check = input.kind_of?(Hash) ? input.size == 1 : false
return false unless check == true
return false unless input.keys[0].kind_of?(String)
ref = input.values[0]
check = ref.kind_of?(Array) ? ref.all? {|x| x.kind_of?(String)} : ref.
kind_of?(String)
return false unless check == true
return false if wk.getObjectByNameAndReference(input.keys[0],[*ref]).empty?
res = wk.getObjectByNameAndReference(input.keys[0],[*ref] ).get
end
ap res.map {|x| "#{x.nameString} : #{x.iddObject.type.valueName}"} if
print_out # print_out come from argument option
return [*res]
end #def
···
On Mon, Jan 1, 2018 at 12:56 PM, Hassan Schroeder < hassan.schroeder@gmail.com> wrote:
On Mon, Jan 1, 2018 at 9:08 AM, ng khanh <cnkhanh1986@gmail.com> wrote:
> i want to set that the def Foo should print out only when i write
> Bar.Foo1(*args).print_out and hide print with Bar.Foo1(*arg) only. Adding
> one more argument is inconvenient for me (too much)
Sorry, not really sure what you're trying to do -- can you post an actual
code snippet and a test that demonstrates what you want?
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
On 2 January 2018 at 08:33, ng khanh <cnkhanh1986@gmail.com> wrote:
hi below of my def with print_out as argument. i would like to print_out as
a method for example self.wk_obs(wk,input,index),print_out to get it prints
out instead input as argument because i have many similar defs like that
thanks
def self.wk_obs(wk,input,index=0,print_out = true) # one only exact
return false unless (0..4).include?index
case index
when 0
return false unless input.is_a?String
res = wk.getObjectsByName(input)
when 1
return false unless check_idd(input)
res = wk.getObjectsByType(input.to_IddObjectType)
when 2
check = input.kind_of?(Array) ? input.all? {|x| x.kind_of?(String)} :
input.kind_of?(String)
return false unless check == true
res = wk.getObjectsByReference(input)
when 3
check = input.kind_of?(Hash) ? input.size == 1 : false
return false unless check == true
return false unless check_idd(input.keys[0])
res = wk.getObjectsByTypeAndName(input.keys[0],input.values[0])
when 4
check = input.kind_of?(Hash) ? input.size == 1 : false
return false unless check == true
return false unless input.keys[0].kind_of?(String)
ref = input.values[0]
check = ref.kind_of?(Array) ? ref.all? {|x| x.kind_of?(String)} :
ref.kind_of?(String)
return false unless check == true
return false if wk.getObjectByNameAndReference(input.keys[0],[*ref]).empty?
res = wk.getObjectByNameAndReference(input.keys[0],[*ref] ).get
end
ap res.map {|x| "#{x.nameString} : #{x.iddObject.type.valueName}"} if
print_out # print_out come from argument option
return [*res]
end #def
On Mon, Jan 1, 2018 at 12:56 PM, Hassan Schroeder > <hassan.schroeder@gmail.com> wrote:
On Mon, Jan 1, 2018 at 9:08 AM, ng khanh <cnkhanh1986@gmail.com> wrote:
> i want to set that the def Foo should print out only when i write
> Bar.Foo1(*args).print_out and hide print with Bar.Foo1(*arg) only.
> Adding
> one more argument is inconvenient for me (too much)
Sorry, not really sure what you're trying to do -- can you post an actual
code snippet and a test that demonstrates what you want?
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
(Obviously you'd want the missing curly braces and everything, and to
make sure #ap is called in the right context, since I've never heard
of that method, etc.)
Cheers
···
On 2 January 2018 at 08:59, Matthew Kerwin <matthew@kerwin.net.au> wrote:
To call #print_out on the object returned from #wks_obj, you have to
make #wks_obj return an object that has a #print_out method.
thanks would check it any other approach is also welcome #ap comes from awesome_print gems (works well in VS Code and Iruby for
prettify data)
···
On Mon, Jan 1, 2018 at 5:00 PM, Matthew Kerwin <matthew@kerwin.net.au> wrote:
On 2 January 2018 at 08:59, Matthew Kerwin <matthew@kerwin.net.au> wrote:
>
> To call #print_out on the object returned from #wks_obj, you have to
> make #wks_obj return an object that has a #print_out method.
>
> Alternatively you could use #tap :
>
> ~~~
> my_thing.wks_obj(wk, input).tap {|res| ap res.map {|x|
> "#{x.nameString} : #{x.iddObject.type.valueName}" }
> ~~~
>
> Cheers
>
(Obviously you'd want the missing curly braces and everything, and to
make sure #ap is called in the right context, since I've never heard
of that method, etc.)
# Create the response class extending Array
class ObsResponse < Array
def print_out
ap self.map {|x| "#{x.nameString} : #{x.iddObject.type.valueName}”}
end
end