This helps to reduce repetition in code. Instead of doing "TYPE_*"
everywhere, you can do include Fiddle::Types, and write the type name
directly.
This PR is to help reduce repetition when writing Fiddle code. Right now
we have to type TYPE_ everywhere, and you also have to include all of Fiddle to access TYPE_* constants. With this change, you can just
include Fiddle::Types and it will shorten your code and also you only
have to include those constants.
Here is an example before:
require"fiddle"moduleMMAP# All Fiddle constants includedincludeFiddledefself.make_functionname,args,retptr=Handle::DEFAULT[name]func=Function.newptr,args,ret,name: namedefine_singleton_methodname,&func.to_procendmake_function"munmap",[TYPE_VOIDP,# addrTYPE_SIZE_T],# lenTYPE_INTmake_function"mmap",[TYPE_VOIDP,TYPE_SIZE_T,TYPE_INT,TYPE_INT,TYPE_INT,TYPE_INT],TYPE_VOIDPmake_function"mprotect",[TYPE_VOIDP,TYPE_SIZE_T,TYPE_INT],TYPE_INTend
After:
require"fiddle"moduleMMAP# Only type names includedincludeFiddle::Typesdefself.make_functionname,args,retptr=Fiddle::Handle::DEFAULT[name]func=Fiddle::Function.newptr,args,ret,name: namedefine_singleton_methodname,&func.to_procendmake_function"munmap",[VOIDP,# addrSIZE_T],# lenINTmake_function"mmap",[VOIDP,SIZE_T,INT,INT,INT,INT],VOIDPmake_function"mprotect",[VOIDP,SIZE_T,INT],INTend
We only need to import the type names, and you don't have to type TYPE_ over and over. I think this makes Fiddle code easier to read.
[ruby/fiddle] Move "type" constants to
Fiddle::Types
(https://github.com/ruby/fiddle/pull/112)This helps to reduce repetition in code. Instead of doing "TYPE_*"
everywhere, you can do
include Fiddle::Types
, and write the type namedirectly.
This PR is to help reduce repetition when writing Fiddle code. Right now
we have to type
TYPE_
everywhere, and you also have to include all ofFiddle
to accessTYPE_*
constants. With this change, you can justinclude
Fiddle::Types
and it will shorten your code and also you onlyhave to include those constants.
Here is an example before:
After:
We only need to import the type names, and you don't have to type
TYPE_
over and over. I think this makes Fiddle code easier to read.https://github.com/ruby/fiddle/commit/49fa7233e5
Co-authored-by: Sutou Kouhei [email protected]